I simply wrote the following code to play around with the Requests library
requests tests
import requests
r = requests.get('https://api.github.com/events')
but I keep getting the same error message, even if I use from requests import *
Traceback (most recent call last):
File "/Users/dvanderknaap/Desktop/Organized/CS/My_Python_Programs/requests.py", line 3, in <module>
import requests
File "/Users/dvanderknaap/Desktop/Organized/CS/My_Python_Programs/requests.py", line 5, in <module>
r = requests.get('https://api.github.com/events')
AttributeError: 'module' object has no attribute 'get'
I've tried reinstalling requests using pip install requests
, but the output is:
Requirement already satisfied (use --upgrade to upgrade): requests in /anaconda/lib/python3.5/site-packages
I think the problem is that it is installed in my python3.5 library but I am using python2.7, but I'm not sure how to fix that. Advice?
First, rename your file My_Python_Programs/requests.py to something else than requests.py. It is importing itself instead of the requests module.
Your python 2.7 may or may not already have the requests package installed. If not, you can install it with
pip2.7 install requests
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With