Skip to content

Instantly share code, notes, and snippets.

@andrewdoss-bit
Created February 17, 2022 02:49
Show Gist options
  • Save andrewdoss-bit/ce47eb7983d94d895c70c222f911176b to your computer and use it in GitHub Desktop.
Save andrewdoss-bit/ce47eb7983d94d895c70c222f911176b to your computer and use it in GitHub Desktop.
Upload json with only requests
import requests
import io
import json
data = {"a": 1, "b": "world"}
buffer = io.StringIO()
json.dump(data, buffer)
buffer.seek(0)
url = 'https://import.bit.io/doss/json_upload/example'
headers = {
"Content-Disposition": "attachment;filename='data.json'",
"Authorization": "Bearer <API_KEY>"
}
response = requests.request("POST", url, headers=headers, data=buffer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment