f



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

Hey,
I am trying to run the following example from
diveintopython

import urllib
sock = urllib.urlopen("http://diveintopython.org/")
htmlSource = sock.read()
sock.close()
print htmlSource

I have Python 2.3.3 but when i run the above code I
get the following error:

raceback (most recent call last):
  File "urllib.py", line 1, in ?
    import urllib
  File
"/home/shalen/programming/python/tutorials/py/urllib.py",
line 2, in ?
    sock =
urllib.urlopen("http://diveintopython.org/")
AttributeError: 'module' object has no attribute
'urlopen'

Anyone knows how to fix this and why I am getting this
error?

Thanks
Dont



~
~
~
~


__________________________________
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools

0
2/23/2004 7:58:45 AM
comp.lang.python 77058 articles. 6 followers. Post Follow

2 Replies
2349 Views

Similar Articles

[PageSpeed] 3

dont bother wrote:

> import urllib
> sock = urllib.urlopen("http://diveintopython.org/")
> htmlSource = sock.read()
> sock.close()
> print htmlSource
> 
> I have Python 2.3.3 but when i run the above code I
> get the following error:
> 
> raceback (most recent call last):
>   File "urllib.py", line 1, in ?
>     import urllib
>   File
> "/home/shalen/programming/python/tutorials/py/urllib.py",
> line 2, in ?
>     sock =
> urllib.urlopen("http://diveintopython.org/")
> AttributeError: 'module' object has no attribute
> 'urlopen'
> 

This is a name clash. As your script has the same name as the library
module, it imports itself instead of urllib in the library.

To fix it, just rename to, say,

/home/shalen/programming/python/tutorials/py/examineurllib.py

Peter
0
__peter__ (4031)
2/23/2004 8:30:15 AM
dont bother wrote:

> Anyone knows how to fix this and why I am getting this
> error?

well, the sample works fine in the shell.  so the error is due to the
different way you refer to external modules when running from a file. 


0
2/24/2004 6:58:00 AM
Reply:

Similar Artilces:

PyKota, Python: AttributeError: 'module' object has no attribute '_quote'
Hello everyone, I'm new to linux/suse, but I was given the task to install the print accounting software PyKota. Before that I never even touched a linux system, so I don't have any basic knowlegde at all! Up to now I was able to solve all problems with the help of google, but now I'm stuck. My problem: linux-6n5c:/usr/local/bin # pkusers --add john paul Creation... ERROR: PyKota v1.26_official ERROR: pkusers failed ERROR: Traceback (most recent call last): ERROR: File "/usr/local/bin/pkusers", line 442, in <module> ERROR: retco...

python+libxml2+scrapy AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER'
Hello. Has anybody already meet the problem like this? - AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER' When I run scrapy, I get File "/usr/local/lib/python2.7/site-packages/scrapy/selector/factories.py", line 14, in <module> libxml2.HTML_PARSE_NOERROR + \ AttributeError: 'module' object has no attribute 'HTML_PARSE_RECOVER' When I run python -c 'import libxml2; libxml2.HTML_PARSE_RECOVER' I get Traceback (most recent call last): File "<string>", line 1, in <module...

AttributeError: 'module' object has no attribute 'pack'
Dear List, I have a freshly installed opensuse 11.2 and I am experiencing the following problem with the module "subprocess": sampsa@linux-912g:~> python Python 2.6 (r26:66714, Feb 3 2009, 20:52:03) [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.6/subprocess.py", line 404, in <module> import p...

AttributeError: 'module' object has no attribute 'letters'
what does this error mean? i am trying to use mark hammonds win32 package. Traceback (most recent call last): File "aui2.py", line 11, in <module> import win32com.client File "C:\Python25\lib\site-packages\win32com\client\__init__.py", line 12, in <module> import dynamic, gencache, pythoncom File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 24, in <module> import build File "C:\Python25\lib\site-packages\win32com\client\build.py", line 507, in <module> valid_identifier_chars = string.le...

AttributeError: 'module' object has no attribute '__path__'
I am using Jupyter notebooks, with Python 3.4. The error below references t= he Anaconda distribution package. This error occurred quite precipitously (= only 2 minutes before I was able to import the modules). I am using Windows= 7. My path in the console uses Python27. I also have python 34 as well. I = am not sure where to start modifying the path and fear that I will break my= initial setup. I welcome feedback on next steps. --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) ...

AttributeError: 'module' object has no attribute 'logger'
hi all, when installing sage, there is a problem with emacs.py so, this screen appeared after rynning ./sage ---------------------------------------------------------------------- | Sage Version 4.4.2, Release Date: 2010-05-19 | | Type notebook() for the GUI, and license() for information. | ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/zid/sage/local/bin/sage-ipython", line 18, in <module> import IPython File "/usr/lib/python2.7/dist-packages/IPython/__init__.py&qu...

AttributeError: 'module' object has no attribute 'HTTPSHandler'
Hi I built and installed python 2.5 from source and when I do this: opener = urllib2.build_opener(SmartRedirectHandler(), DefaultErrorHandler(), urllib2.HTTPSHandler()) I get this error. AttributeError: 'module' object has no attribute 'HTTPSHandler' What should I do? ...

AttributeError: 'module' object has no attribute 'setdefaulttimeout'
I get those errors when I run: /usr/local/bin/SquidClamAV_Redirector.py -c /etc/squid/SquidClamAV_Redirector.conf ################## Traceback (most recent call last): File "/usr/local/bin/SquidClamAV_Redirector.py", line 573, in ? redirector = SquidClamAV_Redirector(config) File "/usr/local/bin/SquidClamAV_Redirector.py", line 145, in __init__ self.__start_urlhandler__() File "/usr/local/bin/SquidClamAV_Redirector.py", line 454, in __start_urlhandler__ urllib.socket.setdefaulttimeout(self.timeout) AttributeError: 'module' object has no ...

AttributeError: 'module' object has no attribute 'fork'
Hi, Code: import os, time def child(pipeout): zzz = 0 while True: time.sleep(zzz) msg = ('Spam %03d' % zzz).encode() os.write(pipeout, msg) zzz = (zzz+1) % 5 def parent(): pipein, pipeout = os.pipe() if os.fork() == 0: child(pipeout) else: while True: line = os.read(pipein, 32) print('Parent %d got [%s] at %s' % (os.getpid(), line, time.time())) parent() Output: Traceback (most recent call last): File "C:/Python34/pipe1.py", line 17, in <module>...

AttributeError: ' ' object has no attribute ' '
I am using Ubuntu 12.10, and Python 2.7.3, GNU Radio Companion v3.6.3. I get the this error in terminal: in __init__ self.wxgui_waterfallsink2_0.set_callback(wxgui_waterfallsink2_0_callback) File "/usr/local/lib/python2.7/dist-packages/gnuradio/gr/hier_block2.py", line 54, in __getattr__ return getattr(self._hb, name) AttributeError: 'gr_hier_block2_sptr' object has no attribute 'set_callback' I have been getting this error in multiple programs. So what is stopping the program here? There is no Attribute .set_callback obviously. But where is t...

'is not' or '!='
A newbie question to you; what is the difference between statements like: if x is not None: and if x != None: Without any context, which one should be preferred? IMHO, the latter is more readable. On 2014-08-18 21:35, ElChino wrote: > A newbie question to you; what is the difference between statements > like: > if x is not None: > and > if x != None: > > Without any context, which one should be preferred? > IMHO, the latter is more readable. > "x == y" tells you whether x and y refer to objects that are equal. "x is y&qu...

'^=' and '~='?
Hello, What is the difference between '^=' and '~='? Thanks, Duckhye ...

logging: AttributeError: 'module' object has no attribute 'getLogger'
Hi all: Being completely new to Python still (just about a week into it now) I tried to follow the Python 2.6.5 version documemtation aiming at setting up a logger as follows: <code> import logging global gPIBLogger class PIBLogger(object): ''' TODO: classdocs ''' def __init__(self, logFileName): ''' Constructor ''' self.logFileName = logFileName self.logger = logging.getLogger('PIBLogger') self.logger.setLevel(logging.DEBUG) hand...

AttributeError: 'Attributes' object has no attribute 'saveFile'
Not sure how to explain, but I'll try my best. I'm making a GUI with wxGlade. The GUI has windows that open when the "Next Page" button is pushed; the button also pickles the information that is input into the frame at the same time. The saveFile name is autocreated based on the data entered by the user in the first frame. Each frame that is created is a new class, e.g. the first frame that opens is "CharInfo", which opens the frame "Attributes". The pickling works for the first frame but doesn't work for the ones after. Apparently the saveFile at...

AttributeError: 'module' object has no attribute 'DatagramHandler' (ubuntu-8.10, python 2.5.2)
$ ~/devel/ice/snoip/freespeech$ python Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import logging >>> logging.DatagramHandler Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute 'DatagramHandler' >>> That is odd since the documentation says there is DatagramHandler for module logging On Mon, Dec 29, 2008 at 4:08 AM, Tz...

AttributeError: 'Or' object has no attribute 'as_independent'
Traceback (most recent call last): File "testcsv.py", line 17, in <module> print(sy.solve([x^2+x+1-t, x^3+x^2-t], x)) File "C:\Python27\lib\site-packages\sympy\solvers\solvers.py", line 902, in so lve solution = _solve_system(f, symbols, **flags) File "C:\Python27\lib\site-packages\sympy\solvers\solvers.py", line 1434, in _ solve_system i, d = _invert(g, *symbols) File "C:\Python27\lib\site-packages\sympy\solvers\solvers.py", line 2422, in _ invert indep, dep = lhs.as_independent(*symbols) AttributeError: 'Or...

'module' object has no attribute 'ssl'
Hi, I have Red Hat Linux 3.2.3-54 and Python 2.4.3 (the original version downloaded from python.org) and I'm using httplib to make a request to an external server, this is the code I'm using: import httplib https = httplib.HTTPSConnection('216.220.59.211', 7989) https.debuglevel = 1 body = buildXML(data) try: https.request('POST', '/Messenger/XMLMessenger', body) response = https.getresponse() response = response.read() https.close() except: response = None import traceback traceback.print_exc() return response And I get the following...

When I do from lxml import etree I've this error : AttributeError: 'module' object has no attribute 'BytesIO'
Hi, I'm on Ubuntu 8.04.1 I've installed lxml with easy_install lxml command. Now, when I load etree I've this error : $ python Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from lxml import etree Traceback (most recent call last): File "<stdin>", line 1, in <module> File "lxml.etree.pyx", line 40, in lxml.etree (src/lxml/ lxml.etree.c:119415) AttributeError: 'module&#...

weird exception : AttributeError: 'module' object has no attribute 'logException'
I am running a script (summary.py) which is calling the method logException in another module ( pytool). Yesterday, ard 18:50, all of a sudden summary.py was throwing the exception : AttributeError: 'module' object has no attribute 'logException' What I did to fix it was to delete the compiled version of the pytool and run again. And it worked again. I am now trying to understand what happened, working with the network admin to see who modified the direcory where pytool is stored. But do you have any idea of what could have happened? All the imports are working, but no m...

ATTRIBUTE ERROR: 'module' object has no attribute 'ssl'
I am getting the following errors: File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 679, in _send_output self.send(msg) File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 646, in send self.connect() File "H:\xampp\xampp\xampp\python\lib\httplib.py", line 1073, in connect ssl = socket.ssl(sock, self.key_file, self.cert_file) AttributeError: 'module' object has no attribute 'ssl' Thank You in Advance johnny wrote: > I am getting the following errors: That is *one* error. > > File "H:\xampp\xampp\xam...

v = vte.Terminal() AttributeError: 'module' object has no attribute 'Terminal'
Hi, I try to run a terminal emulation using Python+Gtk+Vte. Before develop my own sources, i'm testing some examples like this ; http://www.eurion.net/python-snippets/snippet/Embed%20a%20VTE%20terminal.html But when i try to run, i get this message error; v = vte.Terminal() AttributeError: 'module' object has no attribute 'Terminal' I'm using ubuntu 9.10 karmic. I've installed (apt-get) python-gtk, /2, -dev, libvte... Anyone know if there's a bug on this using karmic, or i must to download and compile gtk/vte from sources? thanks, S...

'''''''''''''The Running Update/Append Queries Using VBA code Ordeal''''''''''''''
Hello fellow programmers, I am trying to run an append/update query from code, a command button on a form initiates the queries. the format i am using is; _____________________________________________________ SELECT "criteria" FROM "criteria" WHERE "criteria" UPDATE/APPEND "field selections" RecordSource "qryExample" = above text strings" _______________________________________________________________________ When i am running a SELECT query in this manner it works fine with no problems, and accepts the values of specified linked for...

AttributeError: 'function' object has no attribute 'split'
PathList= string.split(FullPath, "/") is generating the above error message. when I run my script, but works just fine from the python command line! What gives? "Earl" <eee@nmt.edu> wrote in message news:11e5f362.0405060845.16fff0f8@posting.google.com... > PathList= string.split(FullPath, "/") is generating the above error > message. when I run my script, but works just fine from the python > command line! What gives? Somehow you've bound the name "string" to a function e.g. >>> def string(): .... return 'help' ...

AttributeError: 'gr_hier_block2_sptr' object has no attribute 'set_callback'
------=_Part_1122770_31157900.1360876583037 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit I am using ubuntu 12.10 and python version 2.7.3. i run the following command in terminal: matt@matt-Inspiron-1525:~$ python -m trace --count -C . op25_grc.py Here is the output with an error: Imported legacy fsk4 Using Volk machine: ssse3_32 Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main "__main__", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _...

Web resources about - AttributeError: 'module' object has no attribute 'urlopen' - comp.lang.python

Resources last updated: 2/17/2016 6:22:53 PM