我尝试了以下方法:
import requests
requests.get('https://www.google.com')
而且我不断收到此错误:
gaierror: [Errno 11001] getaddrinfo failed
During handling of the above exception, another exception occurred:
NewConnectionError Traceback (most recent call last)
NewConnectionError: <requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x00000194F2F28780>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed
During handling of the above exception, another exception occurred:
MaxRetryError Traceback (most recent call last)
MaxRetryError: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x00000194F2F28780>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',)))
During handling of the above exception, another exception occurred:
ProxyError Traceback (most recent call last)
ProxyError: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x00000194F2F28780>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',)))
尽管,当我尝试使用套接字建立连接时,它也可以正常工作:
socket.getaddrinfo('127.0.0.1', 8080)
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('www.pythonlearn.com', 80))
mysock.send(b'GET http://www.pythonlearn.com/code/intro-short.txt HTTP/1.0\n\n')
响应:
62
请求和套接字尝试建立连接的方式是否有所不同?我认为requests.get()
使用下面的套接字体系结构来发出任何请求。这个假设错了吗?