Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having trouble using requests for urls

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?

like image 860
numbersloth Avatar asked Jan 08 '16 15:01

numbersloth


1 Answers

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
like image 52
JBGreen Avatar answered Oct 22 '22 01:10

JBGreen