简体   繁体   中英

requests.exceptions.ConnectionError [Errno 11004] getaddrinfo failed using Requests in Python. Browser works

I tried my using the requests library of python. Sadly I fail at even the most basic steps. I looked at the quickstart guide here: http://docs.python-requests.org/en/latest/user/quickstart/

Following code fails:

import requests

r = requests.get('http://www.google.com')

with:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='www.google.com', port=80): 
Max retries exceeded with url: / (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x0000000003CC3BA8>: 
Failed to establish a new connection: [Errno 11004] getaddrinfo failed',))

That reads like there was a problem with my network, however opening the same web page in the browser works so it can't be the reason that it's blocking me, can it?

PS copy/pasting the example from the quickstart page and trying to opening ' https://api.github.com/events ' also fails with the same error.

I have found out that in my company they somehow do not provide a DNS server for script requests. That is the reason it did not work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM