它看起來像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