473,846 Members | 1,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

stlib name clash when using python as ASP language

Hi guys, I have couple of simple python based active server pages
that make use of httplib2 which uses gzip.py. IIS, however, also has a
gzip.dll located at the iis/inetsrv path.

When using ASP the iis/inetsrv path is placed as the first item in
sys.path. Consequently importing httplib2 will cause the following
error:

import httplib2
File "c:\python24\li b\site-packages\httpli b2-0.2.0-py2.4.egg
\httplib2\__ini t__.py", line 25, in ?
import gzip
ImportError: dynamic module does not define init function (initgzip)

This is, of course, because it tries to load the gzip.dll file instead
of the gzip.py file.

The following per page hack *fixes* the problem most of the time:
import sys
sys.path[0] = "c:/python24/lib"

Strangely, even with this code loaded in every page the import error
sporadically occurs. What would be the preferred way to solve this
name clash?

Feb 1 '07 #1
3 2748
"Joost" <Jo**********@g mail.comescribi ó en el mensaje
news:11******** **************@ v45g2000cwv.goo glegroups.com.. .
When using ASP the iis/inetsrv path is placed as the first item in
sys.path. Consequently importing httplib2 will cause the following
error:

ImportError: dynamic module does not define init function (initgzip)

The following per page hack *fixes* the problem most of the time:
import sys
sys.path[0] = "c:/python24/lib"

Strangely, even with this code loaded in every page the import error
sporadically occurs. What would be the preferred way to solve this
name clash?
You *assume* that [0] is the IIS path, but perhaps some other imported
module changed sys.path too, and now it's not the first one anymore.
If you know exactly the path, try sys.path.remove (iis_path).

--
Gabriel Genellina
Feb 2 '07 #2
You *assume* that [0] is the IIS path, but perhaps some other imported
module changed sys.path too, and now it's not the first one anymore.
If you know exactly the path, try sys.path.remove (iis_path).

--
Gabriel Genellina
It's was a hack and definitely not meant to go in to production ;)
Since gzip.py lives in python24\lib I thought setting sys.path[0] to
python24\lib would load this load this module, no matter what.
However, in some magically way the sys.path gets modified during the
request by IIS. Maybe IIS resets the global sys.path per new request,
causing sporadic problems when request are handled concurrently? I
just don't know. The iis/inetsrv path is included in sys.path for a
reason and I don't want to fiddle around with sys.path to create
problems in other parts of the code. I was wandering if there is some
way to prevent a name clashes by using a custom importer or something
like that.

Feb 4 '07 #3
En Sun, 04 Feb 2007 09:53:22 -0300, Joost <Jo**********@g mail.com>
escribió:
>You *assume* that [0] is the IIS path, but perhaps some other imported
module changed sys.path too, and now it's not the first one anymore.
If you know exactly the path, try sys.path.remove (iis_path).

It's was a hack and definitely not meant to go in to production ;)
Since gzip.py lives in python24\lib I thought setting sys.path[0] to
python24\lib would load this load this module, no matter what.
However, in some magically way the sys.path gets modified during the
request by IIS. Maybe IIS resets the global sys.path per new request,
causing sporadic problems when request are handled concurrently? I
just don't know. The iis/inetsrv path is included in sys.path for a
reason and I don't want to fiddle around with sys.path to create
problems in other parts of the code. I was wandering if there is some
way to prevent a name clashes by using a custom importer or something
like that.
Python 2.5 has absolute and relative imports, that should handle such
problems in the future.
But in your case I can think of:
- *prepend* python24\lib instead of replacing index 0: sys.path.insert (0,
python24\lib)
- copy gzip.py to another, empty directory, and put *that* directory in
front of sys.path
- play with ihooks.py

--
Gabriel Genellina

Feb 5 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
5237
by: Felix Wiemann | last post by:
Hi! I want to create a module myproject.ui.curses, which needs to import the curses library. However, if I just write ``import curses``, the module imports *itself* instead of the standard library's curses module. Is there any (reliable) way to access a module of the standard library if the names conflict as in this case?
2
2701
by: Olivier Vierlinck | last post by:
Hi, I've a python script using somecalls to the abs() built-in function. Now, I have to import a module named 'abs' too... The consequence if that line code like if (abs(a-b) < epsilon: ... does not work anymore, with this error msg:
3
3828
by: George P | last post by:
I've run into a strange package related namespace problem. Follow these steps (on UNIX system) to illustrate: ------------------------- mkdir /tmp/mypkg cd /tmp/mypkg touch __init__.py echo 'import os\ndef test():\n print os.getcwd()' > os.py cd /tmp
21
1774
by: André | last post by:
Short version of what I am looking for: Given a class "public_class" which is instantiated a few times e.g. a = public_class() b = public_class() c = public_class() I would like to find out the name of the instances so that I could create a list of them e.g.
2
2255
by: Deepa K | last post by:
Hi, In my PC, eth0 is not up because of IP address clash (another PC is using the same IP address). I tried to execute a file which has set of insert commands. After executing the file, when I go and see the database, no rows are inserted. I redirected the output to another file. It shows success for all inserts, but no rows in database. This is happening only when the PC has IP clash, that too not all times. I wasn't able to trace out...
1
1928
by: jipjip | last post by:
Hello all, just new to python.. Suppose i have a directory only with an empty file "pickle.py". In this directory i start the python interpreter and say: What happens? I get an error message: Traceback (most recent call last):
92
3999
by: ureuffyrtu955 | last post by:
Python is a good programming language, but "Python" is not a good name. First, python also means snake, Monty Python. If we search "python" in google, emule, many results are not programming resource. If we search PHP, all results are programming resource. Second, python also means snake, snake is not a good thing in western culture. Many people dislike any things relevant to snake. We must have high regard for the custom.
13
1436
by: Rainy | last post by:
I have a stylistic question. In most languages words in var. name are separated by underscores or cap letters, resulting in var names like var_name, VarName and varName. I don't like that very much because all 3 ways of naming look bad and/or hard to type. From what I understand, scheme can have variables like var-name. I'm curious about reasons that python chose to disallow this. Another question I have is what other languages allow this...
12
1569
by: Abhishek Mishra | last post by:
Hello Everyone, I have the habit of using domain names (of either the application or company) in reverse in package names. for e.g. com.spam.app1 I've recently started a project for an indian domain (tld = .in), which leads to a package name like
0
9879
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10976
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10640
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9477
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7050
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5714
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4111
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.