jdw136
jdw136

Reputation: 168

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.

Upvotes: 12

Views: 49426

Answers (1)

Jon
Jon

Reputation: 332

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.

Upvotes: 3

Related Questions