I'm able to send ZPL commands to my printer using Postman. But when I try it with python (python-requests), it doesn't get to the printer and no response comes back i.e it does not throw an exception, the timeout does not trigger. Is there any restrictions I should be aware of when calling the endpoint from code?
Please see my code below:
<code>
from requests import post
...
response = post(
url="https://api.zebra.com/v2/devices/printers/send",
headers={
"Content-Type": "multipart/form-data",
"apikey": "XXXXX",
"tenant": "XXXXX"
},
files={
'zpl_file': ('label.zpl', open('/home/tunde/Downloads/label.zpl', 'rb')),
'sn': "D2N203900310"
},
timeout=10
)
...
</code>
Any help will be appreciated
3 Replies
I made a bit of progress by using urllib3. This time, I get the following error:
```
b'{"fault":{"faultstring":"Execution of JS-ExtractPrinterList failed with error: Javascript runtime error: \\"TypeError: Cannot read property \\"1\\" from null. (JS-ExtractPrinterList.js:7)\\"","detail":{"errorcode":"steps.javascript.ScriptExecutionFailed"}}}'
```
Can anyone point me in the right direction?
It looks like the server cannot parse the multipart body of the request. If you are able to print out the body of the request, make sure that the format of the body complies with the following format. There should be no additional header in each part and the double quotes are properly placed around the keys, such as "sn", "zpl_file", etc. Sometimes, the Content-Length is placed in the file part by the 3rd party library, which needs to be removed. Otherwise, the extra content header will cause the parser error.
Thank you so much for these tips. It was helpful and I've gotten it to work