Python - Attributeerror: 'module' Object Has No Attribute
I'm trying this simple code: import requests print requests.__file__ r = requests.get('https://github.com/timeline.json') It works flawlessly on the command line when I type the l
Solution 1:
Edit After reading the stacktrace again, you can see that urllib3
tries to import something from the http
module. Your file is called http.py
and is thus imported instead of the expected one.
The actual error happens because of the circular nature of the import. Since requests
hasn't finished importing completely yet. The get
function in requests
isn't defined yet when the http
import reaches import requests
again.
Note: You will also want to always guard your entry point with the if __name__ == '__main__'
construct. This will often avoid nasty errors for unsuspecting future developers (including yourself).
Post a Comment for "Python - Attributeerror: 'module' Object Has No Attribute"