Search code examples
python-3.xtornado

websocket_connect how to pass configured AsyncHTTPClient so could specify proxy?


Using tornado==4.5.3 python==3.5.2

Seems like it could be done via AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient") but where?

@tornado.gen.coroutine
def open(self, proxy=None):
    proxy_host, proxy_port, proxy_username, proxy_password = parse_proxy_dict(proxy)
    connection_request = HTTPRequest(
        url=self.URL, proxy_host=proxy_host, proxy_port=proxy_port,
        proxy_username=proxy_username, proxy_password=proxy_password)
    try:
        self.connection = yield websocket_connect(connection_request)
        self.on_open()
        while True:
            msg = yield self.connection.read_message()
            if msg is None:
                self.on_close()
                break
            yield self.on_message(msg)
    except (Exception, KeyboardInterrupt, SystemExit) as error:
        self.on_error(error)

ws on_error: proxy_host not supported


Solution

  • websocket_connect only uses parts of the AsyncHTTPClient implementation, so it is not affected by AsyncHTTPClient.configure. In particular, it cannot use curl, only tornado.simple_httpclient, which does not support proxies.