Skip to content

Instantly share code, notes, and snippets.

@dunderrrrrr
Created February 21, 2020 13:31
Show Gist options
  • Save dunderrrrrr/fcb48aeadb578e70fbe0a529613f567e to your computer and use it in GitHub Desktop.
Save dunderrrrrr/fcb48aeadb578e70fbe0a529613f567e to your computer and use it in GitHub Desktop.
The requests library is the de facto standard for making HTTP requests in Python.

The requests library is the de facto standard for making HTTP requests in Python. It abstracts the complexities of making requests behind a beautiful, simple API so that you can focus on interacting with services and consuming data in your application.

https://realpython.com/python-requests/

$ pip install requests

GET

import requests
import json

def get_json():
    url = 'http://myurl.com/api.json')
    r = requests.request("GET", url)
    return(r.json())

if __name__ == '__main__':
    data = get_json()
    print(data)

POST

import requests
import json

def json_post():
    payload = {
        "data01": "hello",
        "data02": "world",
    }
    url = 'http://myurl.com/api/')
    r = requests.post(url, data=json.dumps(payload))
    print(r.status_code)

if __name__ == '__main__':
    json_post()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment