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?
- I've modified the settings in "Access control" to the level needed according the documentation of the rest-api (
control
: https://docs.octoprint.org/en/master/api/printer.html#send-an-arbitrary-command-to-the-printer - I've tried three API keys (one in the "Access control", one when clicking on my username --> "user settings", one pushing the button "Manually generate an applicaton key")
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)
- Octoprint Version 1.4.0, running on debian buster 32 bit (LMDE 4.0).
- installed in virtual environment and through pip, in line with: Setting up OctoPrint on a Raspberry Pi running Raspbian