它看起来像client.ProxyAgent没有connectTimeout属性:从Agent
本身同一类Agent
做(_AgentBase
)
class ProxyAgent(_AgentBase):
"""
An HTTP agent able to cross HTTP proxies.
@ivar _proxyEndpoint: The endpoint used to connect to the proxy.
@since: 11.1
"""
def __init__(self, endpoint, reactor=None, pool=None):
if reactor is None:
from twisted.internet import reactor
_AgentBase.__init__(self, reactor, pool)
self._proxyEndpoint = endpoint
def request(self, method, uri, headers=None, bodyProducer=None):
"""
Issue a new request via the configured proxy.
"""
# Cache *all* connections under the same key, since we are only
# connecting to a single destination, the proxy:
key = ("http-proxy", self._proxyEndpoint)
# To support proxying HTTPS via CONNECT, we will use key
# ("http-proxy-CONNECT", scheme, host, port), and an endpoint that
# wraps _proxyEndpoint with an additional callback to do the CONNECT.
return self._requestWithEndpoint(key, self._proxyEndpoint, method,
_URI.fromBytes(uri), headers,
bodyProducer, uri)
ProxyAgent
继承,而不是。
是试图为整个请求设置超时,包括上游HTTP服务器。我发现默认超时时间太短。 – hoju
“Agent”的'connectTimeout'参数不是整个请求超时。这只是TCP连接尝试的超时。我的答案中的代码实现完全相同的事情。如果你想要的不是TCP连接尝试超时,那么我认为你的问题是误导。 –
谢谢,这是有道理的。我设置了此连接超时,并创建了一个包含延迟超时的包装类,以便在往返时间过长时取消请求 – hoju