473,513 Members | 4,753 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Atttribute error

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
4 1814
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4361
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
13
6574
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
7
4979
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
2
19404
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7432
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...
1
7094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5677
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,...
0
4743
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...
0
3230
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...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.