Problems Using Queries for URLs

I just wrote the following code to play around with the query library

requests tests import requests r = requests.get('https://api.github.com/events') 

but I get 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 tried reinstalling the 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 am not sure how to fix it. Advice?

+5
source share
2 answers

First rename the file My_Python_Programs / requests.py to a different place than request.py. It imports itself instead of the query module.

In your python 2.7, a query package can be installed or not. If not, you can install it with

 pip2.7 install requests 
+8
source

Instead of expecting that there is a proper wrapper for your pip with version number, use the pip module of your required Python interpreter:

 % python2.7 -mpip install requests 
0
source

Source: https://habr.com/ru/post/1240179/


All Articles