7

I'm trying to post testing data to a server by using python-requests library in python. I am able to post data successfully with the following command using Curl in the terminal:

curl -i -XPOST 'http://myServerAddress/write?db=some_data' --data-binary 'param1,state=test,param2=1 param3=2.932,param4=3250 1497064544944 ' 

I'm trying to do the same thing with requests or maybe even pycurl python library. I am having a hard time translating the "--data-binary" part with pycurl or requests. Doing something like this with requests library for example:

import requests p = requests.post('http://myServerAddress/write?db=some_data', data={'param1,state=test,param2=1 param3=2.932,param4=3250 1497064544944 '}) print(p) print(p.status_code) print(p.text) 

Getting "TypeError: a bytes-like object is required, not 'set'" in the shell when I run the code. What am I missing? Any help is appreciated. Thanks.

1 Answer 1

7

Try something like this

import requests data='param1,state=test,param2=1 param3=2.932,param4=3250 1497064544944 ' p = requests.post('http://myServerAddress/write?db=some_data', data.encode()) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.