首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何为ProxyAgent设置超时?

如何为ProxyAgent设置超时?
EN

Stack Overflow用户
提问于 2013-12-20 22:03:34
回答 2查看 221关注 0票数 1

client.Agent类有一个连接超时参数:

代码语言:javascript
复制
agent = client.Agent(reactor, connectTimeout=timeout, pool=pool)

如何在使用client.ProxyAgent时设置此超时

代码语言:javascript
复制
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)
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-12-21 20:26:50

传递给TCP4ClientEndpointProxyAgent可以通过超时进行初始化。

代码语言:javascript
复制
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服务器的超时,则无法控制此超时。

票数 2
EN

Stack Overflow用户

发布于 2013-12-20 22:12:46

看起来client.ProxyAgent没有connectTimeout属性:

代码语言:javascript
复制
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本身。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20712646

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档