i just installed the Requests module by using 'easy_insatll' and i tried to run the demo code of this tutrorial,
import requests
payload = {'username': 'xxxx', 'password': 'xxxxx'}
r = requests.get('https://github.com/timeline.json')
but i get this error:
AttributeError: 'module' object has no attribute 'get'
any idea? thanks
You are importing all names from the
requests
module into your local namespace, which means you do not need to prefix them anymore with the module name:If you were to import the module with an
import requests
statement instead, you added the module itself to your namespace and you do have to use the full name:Note that the above examples is what I got from my tests in the interpreter. If you get different results, you are importing the wrong module; check if you have an extra
requests.py
file in your python package:You can also test for the name listing provided by the
requests
module:This is the typical symptom of an unrelated
requests.py
(orrequests.pyc
) file sitting in your current directory, or somewhere else on thePYTHONPATH
. If this is the case, remove or rename it, as it's shadowing the module you really want to import.