Created
August 10, 2021 23:04
-
-
Save andrewdoss-bit/5b9814218245613f185f3e6df99f7786 to your computer and use it in GitHub Desktop.
Upload csv to bit.io from Python w/ requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import pandas as pd | |
# This is to provide a reproducible csv, | |
# you can ignore and use your own csv | |
df_test = pd.DataFrame( | |
data=[[0, 1, 2], [3, 4, 5]], | |
columns=['a', 'b', 'c']) | |
df_test.to_csv('test.csv', index=False) | |
with open('test.csv', 'rb') as f: | |
data = f.read() | |
url = 'https://import.bit.io/<YOUR_USERNAME>/<YOUR_REPO>/test' | |
headers = { | |
"Content-Disposition": "attachment;filename='test.csv'", | |
"Authorization": "Bearer <YOUR_API_KEY>" | |
} | |
response = requests.request("POST", url, headers=headers, data=data) | |
print(response.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment