I'm using pythons Requests to send a Pandas Dataframe to a Flask server. The dataframe has about 2 million rows and 16 columns. I want to send a config dictionary along with the dataframe, as metadata. At the moment I am able to send the dataframe as a JSON file, however, I can't find any way to attach the metadata in the same post request.
Here's my code:
Client side:
# Post request containing 1. The dataset (pandas df) 2. The metadata (dict)
dataset = dataset.to_json(orient='split')
metadata = {'dataset ID': "makis", 'date start': "1", 'date end': "2"}
url = "http://localhost:8081/upload_dataset"
r = requests.post(url, data=dataset)
return r.text
Server side:
@app.route("/upload_dataset", methods=['POST'])
def upload_dataset():
from werkzeug.datastructures import FileStorage
payload = request.stream
dataset = pd.read_json(payload, typ='frame', orient='split')
FileStorage(payload).save('dataset.csv')
return 'File Uploaded & Standing by', 200