Python Requests: NewConnectionError

Viewed 34088

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.

1 Answers
Related