How to fix the error? AttributeError: 'module' object doesn't have 'client' attribute in python3?

Below is the code.

import http
h1 = http.client.HTTPConnection('www.bing.com')

I think this is normal. But python gives me the following error:

AttributeError: the 'module' object does not have the 'client' attribute.

I wanted to know why and how to fix it. Thank.

+4
source share
1 answer

At first, importing a package does not automatically import all its submodules. *

So try the following:

import http.client

If this does not work, then most likely you have a file with a name http.pyor a directory with a name httpsomewhere else on yours sys.path(most likely in the current directory). You can check this out quite easily:

import http
http.__file__

, /usr/lib/python3.3/http/__init__.py /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/http/__init__.py, - , system-y stdlib-y; /home/me/src/myproject/http.py, . , , , stdlib, .


, Python Python, . , Python PYTHONPATH, Python , , python.


* . . , - (, http) (os). , ; import os.path import http.client, .

+5

All Articles