即使socket.socket()。connect工作正常,request.get()也会失败(Python 3)

时间:2018-12-25 11:02:14

标签: python python-requests

我尝试了以下方法:

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()使用下面的套接字体系结构来发出任何请求。这个假设错了吗?

0 个答案:

没有答案