简体   繁体   中英

How to import csv file to QuestDb from Python?

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--

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM