Skip to content

Instantly share code, notes, and snippets.

@VITIMan
Created September 4, 2017 07:39
Show Gist options
  • Save VITIMan/f3400cbc5fa053d18e8a785e47f879b0 to your computer and use it in GitHub Desktop.
Save VITIMan/f3400cbc5fa053d18e8a785e47f879b0 to your computer and use it in GitHub Desktop.
Requests library snippets
import requests
import json
# from https://stackoverflow.com/a/35534695
payload = [{"json": "array"}, {"another": "element"}]
headers = {'Content-Type': 'application/json', 'Accept':'application/json'}
requests.post(url,data=json.dumps(payload), headers=headers)
# In newer versions of requests
# from https://stackoverflow.com/a/35535240
requests.post(url, json=payload, headers=headers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment