How to import csv file to QuestDb from Python?

Viewed 251

I'm trying to import file to Questdb as REST csv upload. My code looks like

import requests
with open('..\data.csv', 'rb') as f:
    r = requests.post('http://localhost:9000/imp?name=weekly3', files={'data.csv': f})
    print(r.text)

However I get back

{"status":"invalid value in 'Content-Disposition' multipart header"}

I do not see anything wrong with Content-Disposition when I dump the request

POST http://localhost:9000/imp?name=weekly3
Content-Length: 197
Content-Type: multipart/form-data; boundary=23ef3f7581b79898155acd5567e0b455
--23ef3f7581b79898155acd5567e0b455
Content-Disposition: form-data; name="data.csv"; filename="data.csv"
C:\Users\allnau\Downloads\data.csv
--23ef3f7581b79898155acd5567e0b455--
1 Answers

In your files dictionary csv should be under data key.

import requests
with open('..\data.csv', 'rb') as f:
    r = requests.post('http://localhost:9000/imp?name=weekly3', files={'data': f})

As per curl examples, QuestDb accepts data and schema form parts at ?imp endpoint

Related