Adding headers to requests module

linkaiyi
Follow

Adding headers to requests module

url = 'https://api.github.com/some/endpoint'
payload = {'some': 'data'}
headers = {'content-type': 'application/json'}

r = requests.post(url, data=json.dumps(payload), headers=headers)

How to get response data

>>> import requests
>>> response = requests.get("http://www.google.com")
>>> print response.content
'<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage"><head>....'
>>> print response.content == response.text
True
Object has 0 attachments

Was this article helpful?

This article is viewed 22 times!

Recent Viewed Articles

Related Articles

0 Comments

Leave a Comment

Support