No Response From SendFileToPrinter

// Expert user has replied.
B Babatunde Akinyanmi 2 years 8 months ago
26 3 0

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&quot;,
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

Please Register or Login to post a reply

3 Replies

B Babatunde Akinyanmi

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?

S Steven Si

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.

--203fab52-5a95-4e51-9e5c-53248aae2256
Content-Disposition: form-data; name="sn"

XXZJJ174600934
--203fab52-5a95-4e51-9e5c-53248aae2256
Content-Disposition: form-data; name="zpl_file"; filename="HelloWorld.txt"
Content-Type: text/plain

^XA^FO50,50^ADN,36,20^FDHello World!^FS^XZ
--203fab52-5a95-4e51-9e5c-53248aae2256--

 

B Babatunde Akinyanmi

Thank you so much for these tips. It was helpful and I've gotten it to work

CONTACT
Can’t find what you’re looking for?