client.Agent类有一个连接超时参数:
agent = client.Agent(reactor, connectTimeout=timeout, pool=pool)如何在使用client.ProxyAgent时设置此超时
auth = base64.b64encode("%s:%s" % (username, password))
headers['Proxy-Authorization'] = ["Basic " + auth.strip()]
endpoint = endpoints.TCP4ClientEndpoint(reactor, host, port)
agent = client.ProxyAgent(endpoint, reactor=reactor, pool=pool)发布于 2013-12-21 20:26:50
传递给TCP4ClientEndpoint的ProxyAgent可以通过超时进行初始化。
auth = base64.b64encode("%s:%s" % (username, password))
headers['Proxy-Authorization'] = ["Basic " + auth.strip()]
endpoint = endpoints.TCP4ClientEndpoint(reactor, host, port, timeout=yourTimeout)
agent = client.ProxyAgent(endpoint, reactor=reactor, pool=pool)这是假设您希望设置连接到代理的超时。如果希望设置代理用于连接到上游HTTP服务器的超时,则无法控制此超时。
发布于 2013-12-20 22:12:46
看起来client.ProxyAgent没有connectTimeout属性:
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继承的是Agent not (_AgentBase)类,而不是Agent本身。
https://stackoverflow.com/questions/20712646
复制相似问题