How do I send the ASCII encoded text via POST request in Python? The length of true_input I received via the POST is always different from the length I sent.
def insert_true_input(level, iteration, true_input):
url = master_url + "/insert_true_input?"
data = {'level': level, 'iteration': iteration, 'true_input': true_input}
headers = {'Content-Type': 'text/plain'}
res = requests.post(url, params=data, headers=headers).text
return res
The sample true_input that I want to send is directly from numpy.ndarray.tostring() and looks like
'\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x08@\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x007@\x00\x00\x00\x00\x00\xc0^@\x00\x00\x00\x00\x00\xc0^@\x00\x00\x00\x00\x00\xc0^@\x00\x00\x00\x00\x00\x00(@\x00\x00\x00\x00\x00\x00?@'
paramsparameter torequests.post(), you are actually using a query string to post your data, not the request body. If you want to pass it as body, use thedataparameter instead, and remove your custom Content-Type header (requests will use Content-Typeapplication/x-www-form-urlencodedautomatically).\x00. That is not something easy to pass by text. Can you encode it using base64 first ? Do you have control over the other side which will receive the request ?