Python requests

From wikinotes

Documentation

official docs https://2.python-requests.org/en/master/

Usage

import requests

url = 'http://localhost:5000/test'
headers = {'Content-Type': 'application/json; charset=utf-8'}
json_data = '{"user": "me"}'
reply = requests.get(url=url, headers=headers, data=json_data)

if 200 <= reply.status_code < 300:
    print('success')

# TODO: check headers
reply.json
# TODO: retrieve non-json data

Response

See response object documentation https://werkzeug.palletsprojects.com/en/0.15.x/wrappers/

reply._content     # raw bytestring with reply
reply.status_code  # http status