By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,089 Members | 2,359 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,089 IT Pros & Developers. It's quick & easy.

Atttribute error

P: n/a
The snippet below causes an attribute error.

AttributeError: module 'urllib' has no attribute 'urlopen'

I am using python 2.2.3. According to the documentation at C:
\Python22\Doc\lib urllib has a function called urlopen.

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import urllib

class login(CompactTest):
# Recorded test actions.
def runTest(self):
f = urllib.urlopen("http://www.python.org/")
f.read()

May 8 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
In <11*********************@p77g2000hsh.googlegroups. com>, HMS Surprise
wrote:
The snippet below causes an attribute error.

AttributeError: module 'urllib' has no attribute 'urlopen'

I am using python 2.2.3. According to the documentation at C:
\Python22\Doc\lib urllib has a function called urlopen.
Do you have a file called `urllib.py` in the current directory? Then this
gets imported instead of the module in the standard library.

Add this directly after the ``import`` to see what's happening:

print urllib.__file__
print dir(urllib)

Ciao,
Marc 'BlackJack' Rintsch
May 8 '07 #2

P: n/a
On May 8, 11:37 am, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
In <1178641784.974581.14...@p77g2000hsh.googlegroups. com>, HMS Surprise
wrote:
The snippet below causes an attribute error.
AttributeError: module 'urllib' has no attribute 'urlopen'
I am using python 2.2.3. According to the documentation at C:
\Python22\Doc\lib urllib has a function called urlopen.

Do you have a file called `urllib.py` in the current directory? Then this
gets imported instead of the module in the standard library.

Add this directly after the ``import`` to see what's happening:

print urllib.__file__
print dir(urllib)

Ciao,
Marc 'BlackJack' Rintsch
Thanks for posting Marc.

I do have a file named `urllib.py` in the current directory. I copied
it from 'C:\Python22\Lib' as I could not get rid of the 'no module
named urllib' error message, even though I appended 'C:\Python22\Lib
to sys.path'. This changed the error from module not found to a no
attribute msg.

The maxq program (IDE?, runtime enviroment? , shell?) apparently uses
jython so maybe sys.path is not the problem. This is the reason for my
thread 'sys.path'.

Thanks again,

jh

May 8 '07 #3

P: n/a
PS

Add this directly after the ``import`` to see what's happening:

print urllib.__file__
print dir(urllib)
C:\maxq\bin\testScripts\.\urllib.py
['__doc__', '__file__', '__name__', 'string']

May 8 '07 #4

P: n/a
En Tue, 08 May 2007 13:54:31 -0300, HMS Surprise <jo**@datavoiceint.com>
escribió:
>print urllib.__file__
print dir(urllib)

C:\maxq\bin\testScripts\.\urllib.py
['__doc__', '__file__', '__name__', 'string']
Perhaps you get an import error and it got unnoticed? I think earlier
Python versions could leave a partially initialized module in sys.modules,
and Jython could suffer that. Because the first thing urllib does is to
import string, and the second, to import socket. Maybe it can't find
socket.py or its dependencies (that's not surprising, if Jython could not
find urllib.py in the first place).
So copying individual modules from the library isn't a good solution -
you'd have to copy a lot of things in order to fulfill the growing import
requirements. Best is to make Jython find its library - if Jython was
installed on C:\Jython, it should be at C:\Jython\Lib. Follow the advice
from John Machin on the other thread.

--
Gabriel Genellina

May 9 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.