Working with http

Standard library reference for request

However the library often used is called "requests"

Requests: http for humans link

Search for: Requests: http for humans link

Home page for requests module


pip install requests

import requests
r = requests.get(url)

datamap = {key:value, key:value}

r = requests.post(url, data=datamap)

r = requests.post(url, data=datamap)

r.url
r.text
r.encoding
r.content #binary
r.json()
r.status_code
r.raise_for_status()

Examples


headers = {'user-agent': 'my-app/0.0.1'}
r = requests.get(url, headers=headers)

r.status_code
200 is good
r.raise_for_status()
r.headers

{
    'content-encoding': 'gzip',
    'transfer-encoding': 'chunked',
    'connection': 'close',
    'server': 'nginx/1.0.4',
    'x-runtime': '148ms',
    'etag': '"e1ca502697e5c9317743dc078f67693f"',
    'content-type': 'application/json'
}