Using tornado.httpclient.AsyncHTTPClient.fetch() to make a GET request along with parameters

Hashken picture Hashken · Jun 25, 2013 · Viewed 12.5k times · Source

As mentioned in the title, i want to make a asynchronous GET request using the fetch() method of AsyncHTTPclient.

But, I can't figure out where to give the query parameters.

So, say I want to make the request

http://xyz.com?a=1&b=2

where do I give the a and b? Is the only way to do this is by appending the parameters to the URL. Specifically, is there a way to pass a Dict which then gets appended to the URL by the Tornado framework.

Answer

vartec picture vartec · Jun 25, 2013
from tornado.httputil import url_concat
params = {"a": 1, "b": 2}
url = url_concat("http://example.com/", params)

http_client = AsyncHTTPClient()
http_client.fetch(url, request_callback_handler)