This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ImportError of urllib.request & http.client under PYTHONHOME/Lib
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, mikezp59
Priority: normal Keywords:

Created on 2009-10-14 04:57 by mikezp59, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
http.py mikezp59, 2009-10-14 04:56 python code
Messages (2)
msg93965 - (view) Author: mike (mikezp59) Date: 2009-10-14 04:56
There's a python program in the attached file http.py, I import
urllib.request in http.py, and urllib.request imports http.client.

  When I try to run http.py by command "python http.py", the error is as
below:

Traceback (most recent call last):
  File "http.py", line 4, in <module>
    import urllib.request
  File "C:\Program Files\Python311\lib\urllib\request.py", line 86, in
<module>
    import http.client
  File "D:\program\python\http.py", line 6, in <module>
    response = urllib.request.urlopen('http://python.org/')
AttributeError: 'module' object has no attribute 'request'


   However, if I copy http.py to directory PYTHONHOME/Lib and run
command "python http.py" under directory PYTHONHOME/Lib, it works
successfully; if you move it to other directories and run the command,
the error will be returned.


   Note: the source code of http.py is copied from python311.chm under
directory PYTHONHOME/Doc.
msg93966 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-10-14 05:22
Your file is named 'http.py'. When urllib.request tries to import
http.client your file ("D:\program\python\http.py") is picked up first
instead of the right one ('C:\Program Files\Python311\lib\http\client.py').
Your file is then executed again and when it calls urllib.request,
urllib has not been completely imported yet, so the call fails.
Try to use another name for your program.
History
Date User Action Args
2022-04-11 14:56:53adminsetgithub: 51370
2009-10-14 05:22:42ezio.melottisetstatus: open -> closed

type: compile error -> behavior

nosy: + ezio.melotti
messages: + msg93966
resolution: not a bug
stage: resolved
2009-10-14 04:57:03mikezp59create