简体   繁体   English

在Python中将代理与httplib2一起使用时发生超时错误

[英]Timeout Error when using proxy with httplib2 in Python

i have a simple code that uses proxy to submit a "GET" request to google . 我有一个简单的代码,该代码使用代理向Google提交“ GET”请求。

import httplib2

http = httplib2.Http(proxy_info = httplib2.ProxyInfo(proxy_type=3,proxy_host=myProxy, proxy_port=myPort))
resp, content = http.request("http://google.com", "GET")
print(resp)
print(content)

For some reason i get a Timeout error : 由于某种原因,我收到超时错误:

    resp, content = http.request("http://google.com", "GET")
  File "C:\Python35\lib\site-packages\httplib2\__init__.py", line 1322, in requ
st
    (response, content) = self._request(conn, authority, uri, request_uri, meth
d, body, headers, redirections, cachekey)
  File "C:\Python35\lib\site-packages\httplib2\__init__.py", line 1072, in _req
est
    (response, content) = self._conn_request(conn, request_uri, method, body, h
aders)
  File "C:\Python35\lib\site-packages\httplib2\__init__.py", line 995, in _conn
request
    conn.connect()
  File "C:\Python35\lib\http\client.py", line 849, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "C:\Python35\lib\socket.py", line 711, in create_connection
    raise err
  File "C:\Python35\lib\socket.py", line 702, in create_connection
    sock.connect(sa)
TimeoutError: [WinError 10060] A connection attempt failed because the connecte
 party did not properly respond after a period of time, or established connecti
n failed because connected host has failed to respond

I'm using a valid proxy, but this module doesn't works, Does anybody knows why this happened? 我使用的是有效的代理服务器,但该模块不起作用,有人知道为什么会这样吗?

Win Error 10060 means that no connection can be made and that either the host or the connection(proxy) is at fault. Win Error 10060表示无法建立连接,并且主机或连接(代理)有故障。 Since google is virtually never down we can narrow down the problem to the proxy configuration. 由于google实际上从来没有崩溃,我们可以将问题缩小到代理配置。

Since you seemingly configured the proxy correctly (assuming you pass the right types and arugments ) you might want to check what SOCKS protocol the server additionally supports. 由于您似乎正确配置了代理(假设您传递了正确的类型和arugments),因此您可能需要检查服务器还支持哪些SOCKS协议。

Either your're not passing valid values as a proxy configuration or it is the server's fault. 您没有传递有效值作为代理配置,或者是服务器的故障。


You could also try to diagnose with wireshark to see if any packets even make it to the server. 您也可以尝试使用Wireshark进行诊断,以查看是否有任何数据包发送到服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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