Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
[Tornado AsyncHTTPClient POST form params example] #python #tornado #post #httpclient #asynchttpclient
import urllib
def handle_request(http_response):
# do something with HTTPResponse object
post_data = { 'data': 'test data' }
body = urllib.parse.urlencode(post_data)
http_client.fetch("", handle_request, method='POST', headers=None, body=body)
# handle_request callback can be omitted (and in fact is deprecated since Tornado version 5.1)
response = await http_client.fetch("", method='POST', headers=None, body=body)
# synchronous api
# response =
# except urllib.error.HTTPError as exc:
# async implementation
api_endpoint = ''
headers = {'Authorization': f'Bearer {sendgrid_api_key}',
'Content-Type': 'application/json'}
json_data = json.dumps(data)
response = await http_client.fetch(api_endpoint,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.