Osterberg
Osterberg

Reputation: 31

Post string as FORMDATA in python

I'm trying to replicate this cURL onliner:

curl -i -XPOST 'http://httpbin.org/post?db=data' --data-binary 'files,host=server10,folder=max value=0.64 1434055562121200000'

to python with the help of python-requests.

I've tried:

import requests
payload = {'files,host=server10,folder=max value=0.64 1434055562121200000':'\n'}
or payload = {'files,host':'server10,folder=max value=0.64 1434055562121200000'}
or {'files,host=server10,folder=max value=0.64 1434055562121200000':''}
or {'files,host=server10,folder=max value=0.64 1434055562121200000'}

r = requests.post('http://httpbin.org/post?db=data', data=payload)

I need some pointers or help to get past this snag, because it's possible right?

Upvotes: 2

Views: 1563

Answers (1)

Osterberg
Osterberg

Reputation: 31

Answering my self.

import requests
url = 'http://10.10.10.10:8086/write?db=data'
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
payload = "cpu,host=server01,region=us-west value=0.64 1434055562000000000\n"
r = requests.post(url, data=payload, headers=headers)

With this, posting to influxdb via python works the same as the above cURL onliner.

Upvotes: 1

Related Questions