Post requests result in tornado access warning

What is the problem?
I can't successfully run post requests through the REST api.
e.g. following python code:

headers_octoprint={
    'Host': '192.168.0.xxx',
    'X-Api-Key': 'xxxxxxx',
}

payload={'command': 'M114'}

url='http://'+address_octo+':5000/api/printer/command'
response = post(url,data=payload,headers=headers_octo)

headers_octoprint2={
    'Host': '192.168.0.xxx',
    'X-Api-Key': 'xxxxx',
    'command': 'M114'
}

url='http://'+address_octo+':5000/api/printer/command'
response = post(url,headers=headers_octoprint2)

gives me errors and warnings in the octoprint log:

2020-07-10 07:05:15,712 - tornado.access - ERROR - 500 POST /api/printer/command (192.168.0.xxx) 6.78ms
2020-07-10 07:05:34,781 - tornado.access - WARNING - 400 POST /api/printer/command (192.168.0.xxx) 7.66ms

executing GET requests however, returns information as expected ... .

What did you already try to solve it?

Logs (octoprint.log, serial.log or output on terminal tab at a minimum, browser error console if UI issue ... no logs, no support!)

output in octoprint window:

2020-07-10 07:05:15,712 - tornado.access - ERROR - 500 POST /api/printer/command (192.168.0.xxx) 6.78ms
2020-07-10 07:05:34,781 - tornado.access - WARNING - 400 POST /api/printer/command (192.168.0.xxx) 7.66ms

result python:

>>> response = post(url,data=payload,headers=headers_octo)
>>> response
<Response [400]>
>>> response.text
'Expected content type JSON'

Additional information about your setup (OctoPrint version, OctoPi version, printer, firmware, browser, operating system, ... as much data as possible)

Not just log excerpts please but the full unedited unabridged logs.

The response already tells you what the problem is though, you forgot to set the correct content type on your request.

https://docs.octoprint.org/en/master/api/general.html#content-type

ok thanks, that was pretty stupid :slight_smile: For the ones with the same problem and trying it in python, some working code is below ... .

headers_octoprint={
    'content-type': 'application/json',
    'Host': '192.168.0.xxx',
    'X-Api-Key': 'xxxxx',
}

data = {}
data['command'] = 'M114'
payload = json.dumps(data)
url='http://'+address_octo+':5000/api/printer/command'
response = post(url,data=payload,headers=headers_octo)
temp=response.text