Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Pickup proxy settings from http_proxy environment variable #754

prongs opened this Issue · 5 comments

2 participants


I made an app with facebook login and since I'm behind proxy, I'm having trouble getting access token. My handler class is subclassed from FacebookGraphMixin and in the function get_authenticated_user, it calls the function fetch of an http client obtained by self.get_auth_http_client. Now I thought I could overwrite get_auth_http_client to manually set proxy in the resulting client but I don't see any way of setting proxy for AsyncHTTTPClient. The proxy can only be set on an HTTPClient which is instantiated by AsyncHTTPClient in the function fetch. Now it does not make sense to also have to subclass AsyncHTTPClient and HTTPClient, I suggest while initializing HTTPClient, we set proxy_host and proxy_port according to the environment variable http_proxy. This is a standard way of setting proxy for python applications. Many python applications including pip and easy_install also use this, .


The default AsyncHTTPClient implementation (simple_httpclient) doesn't support proxies at all. The alternative, curl_httpclient, supports proxies and I believe will use the http_proxy environment variable automatically.

See the docs at
to configure your application to use curl_httpclient instead of simple_httpclient. If curl_httpclient doesn't pick up the environment variable automatically, you can pass 'defaults={'proxy_host': '...'}' as a keyword argument to AsyncHTTPClient.configure (this needs to be documented).


I tried with



    AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient", defaults=dict(proxy_host='x.y.z.w', proxy_port=3128))

but still I get

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\tornado\", line 1019, in wrapper
    return callback(*args, **kwargs)
  File "C:\Python27\lib\site-packages\tornado\", line 1143, in _on_access_token
    future.set_exception(AuthError('Facebook auth error: %s' % str(response)))
  File "C:\Python27\lib\site-packages\tornado\", line 87, in set_exception
  File "C:\Python27\lib\site-packages\tornado\", line 97, in _set_done
  File "C:\Python27\lib\site-packages\tornado\", line 88, in _auth_future_to_callback
  File "c:\Users\Rajat\Documents\GitHub\Testimonial\", line 75, in _on_auth
    raise HTTPError(500, "Facebook auth failed")
HTTPError: HTTP 500: Internal Server Error (Facebook auth failed)

with tornado version 3.0.1.

I put the configure call before starting the application and server. Is that correct place for it?


I do get the following warning in the console:

WARNING:tornado.general:Facebook auth error: HTTPResponse(_body=None,buffer=None,code=599,effective_url='',error=CurlError('HTTP 599: SSL certificate problem: unable to get local issuer certificate',),headers={},reason='Unknown',request=<tornado.httpclient.HTTPRequest object at 0x02B60710>,request_time=1.2690000534057617,time_info={})
WARNING:tornado.general:500 GET /auth/login?next=%2F&code=something (::1): Facebook auth failed
ERROR:tornado.access:500 GET /auth/login?next=%2F&code=something (::1) 1283.00ms

It looks like your configure call is fine. The curl error indicates that your curl installation is missing its root certificate list (or that the server you're talking to does not have a valid certificate). If it's the former, see this page for information on making curl use your OS-provided SSL certificate list or installing a copy of the mozilla list.


This worked:

defaults = dict(ca_certs=certifi.where())
http_proxy = os.environ.get('http_proxy')
if http_proxy:
    if http_proxy[:7] == "http://":
        http_proxy = http_proxy[7:]
    defaults['proxy_host'], defaults['proxy_port'] = http_proxy.split(":")
    defaults['proxy_port'] = int(defaults['proxy_port'])

AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient", defaults=defaults)
@prongs prongs closed this
@kakawait kakawait referenced this issue in jakubroztocil/lastfmclient

Support http proxy #2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.