Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Requests: NewConnectionError

I am using Python, and the Requests Module. But whenever I use 'requests.get' with a URL, I get the error:

Traceback (most recent call last):
File "python", line 15, in <module>
requests.exceptions.ConnectionError: HTTPSConnectionPool
(host='www.google.com', port=443): Max retries exceeded with url: /?     
safe=active&gws_rd=ssl&safe=active (Caused by NewConnectionError   
('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at   
0x7f86809a16a0>: Failed to establish a new connection: [Errno -2] Name or 
service not known',))

Here is my code:

try:
    import requests
except ImportError:
    print ("Error: MOD.01")
r = requests.session()
url = "https://www.google.com/?safe=active&gws_rd=ssl&safe=active"
r2 = requests.get(url)

Is it something with my code that is triggering the error? Thanks.

like image 294
jdw136 Avatar asked Aug 08 '17 19:08

jdw136


1 Answers

The error you are getting is "Name or service not known". This means that the server cannot find an IP address for www.google.com

Make sure you copy / pasted everything correctly and then next from the same shell you are running the python script from, see if you can ping www.google.com

It could be as simple as the network (or DNS) isn't configured for that machine / shell.

like image 168
Jon Avatar answered Nov 15 '22 07:11

Jon