# Failure to send binary data greather than 64KB using Requests

**URL:** <https://forum.inductiveautomation.com/t/failure-to-send-binary-data-greather-than-64kb-using-requests/31647>\
**Category:** Ignition\
**Tags:** ignition80, scripting\
**Created:** [January 27, 2020, 5:22pm UTC](https://forum.inductiveautomation.com/t/failure-to-send-binary-data-greather-than-64kb-using-requests/31647 "2020-01-27T17:22:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpoitras](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@jpoitras](https://forum.inductiveautomation.com/u/jpoitras)\
**Post date:** [January 27, 2020, 5:22pm UTC](https://forum.inductiveautomation.com/t/failure-to-send-binary-data-greather-than-64kb-using-requests/31647/1 "2020-01-27T17:22:35Z")

</div>

I'm trying to send an image to an Azure vision endpoint. The data stored in the DB looks something like this.

DB Value:  
array('b', [-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73 .. etc

Its converted to a byteArray to be packaged as the data  
Byte Array Value:  
�PNG

IHDR����r8gAMA���a .....etc

The basic endpoint definition and instructions are the following.  
[https://eastus2.api.cognitive.microsoft.com/customvision/v3.0/Prediction/](https://eastus2.api.cognitive.microsoft.com/customvision/v3.0/Prediction/)[project id]/classify/iterations/[iteration Name]/image  
Set Prediction-Key Header to : _key value_  
Set Content-Type Header to : application/octet-stream  
Set Body to :

> [@system.net.httpPost is not binary safe](http://forum.inductiveautomation.com/t/system-net-httppost-is-not-binary-safe/11345):
>
> Using system.net.httpPost to send arbitrary data is not binary safe. Only tested on 7.8.2-rc1 From the manual: [quote]You can post arbitrary data as well, but you’ll need to specify the MIME type. The document is then returned as a string. [/quote] eg sending a 1x1 pixel png by way of example in the attached txt file shows the corruption of the sent data. [attachment=0]httpPost.txt[/attachment] For headers and data as indicated in file #this works import urllib2 request = urllib2.Request…

We had initially tried using the built in Ignition function, system.net.httpPost as our method to send the images to the endpoint, but we kept getting a “Bad Image Format” error returned from Azure.  
The post hints about it being an issue with the byteArray, but from our testing it seems to be something happening in httpPost.

Next we pivoted to using the python libraries: Request (backed by URLLIB3)

> **[requests](https://pypi.org/project/requests/)**
>
> Python HTTP for Humans.

• Using the requests library within the Ignition platform, sending images that are less than 64K works successfully as expected  
• Using the requests library within the Ignition platform, sending images that are greater than 64K do not work successfully. We receive a timeout with a ConnectionAborted: BadLineStatus(‘’’’)  
o Setting the Content-Length value in the header didn’t help either unfortunately.

As a validation step, I simply did an install of python 3.7, loaded up requests and urllib3 library and performed the exact same calls (fetched data from our database, called out to the Azure endpoint).  
• Using the requests library from the command line against python sending images that are less than 64K works successfully as expected  
• Using the requests library from the command line against python, sending images that are greater than 64K works successfully as expected

This may be relevant - [jython 2.7.1 limits size of http 'post' · Issue #2535 · ControlSystemStudio/cs-studio · GitHub](https://github.com/ControlSystemStudio/cs-studio/issues/2535)

I understand that there are a lot of moving parts here…  
• Ignition is jython - 2.7  
• Requests and urllib3 are additional libraries  
• The external test we performed where it works isn’t a good 1 to 1 representation, but it took the Ignition system / JVM out of the equation..

Since we can’t get the call to fail in the same way outside of the ignition environment, we’re struggling to get a good understanding as to why or where in the pipeline its failing. Any ideas about where this might be failing or a different method that is known to work for this kind of problem would be great.  
I'd like to avoid creating a custom module just to get around this.

Thanks

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 27, 2020, 5:27pm UTC](https://forum.inductiveautomation.com/t/failure-to-send-binary-data-greather-than-64kb-using-requests/31647/2 "2020-01-27T17:27:29Z")

</div>

[https://bugs.jython.org/issue2618](https://bugs.jython.org/issue2618)  
Looks like the root cause.  
I’d suggest giving [`system.net.httpClient`](https://docs.inductiveautomation.com/display/DOC80/system.net.httpClient) a try - it’s using the purely Java [`HttpClient`](https://docs.oracle.com/en/java/javase/11/docs/api/java.net.http/java/net/http/HttpClient.html) class under the hood, so there’s nowhere that uses Jython internals like the `socket` library.

---

<div class="post-metadata">

**Author:** ![jpoitras](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@jpoitras](https://forum.inductiveautomation.com/u/jpoitras)\
**Post date:** [January 27, 2020, 10:15pm UTC](https://forum.inductiveautomation.com/t/failure-to-send-binary-data-greather-than-64kb-using-requests/31647/3 "2020-01-27T22:15:24Z")

</div>

Aces. The httpClient does indeed help us get around this problem. Much appreciated.

---

<div class="post-metadata">

**Author:** ![omar.arellano](https://avatars.discourse-cdn.com/v4/letter/o/b487fb/32.png) [@omar.arellano](https://forum.inductiveautomation.com/u/omar.arellano)\
**Post date:** [October 8, 2021, 8:27pm UTC](https://forum.inductiveautomation.com/t/failure-to-send-binary-data-greather-than-64kb-using-requests/31647/4 "2021-10-08T20:27:34Z")

</div>

Can you give some example with the request post method to sendPhoto  
using system.net.httpClient

Please

---

<div class="post-metadata">

**Author:** ![m.sanders](https://avatars.discourse-cdn.com/v4/letter/m/df705f/32.png) [@m.sanders](https://forum.inductiveautomation.com/u/m.sanders)\
**Post date:** [April 12, 2022, 1:43pm UTC](https://forum.inductiveautomation.com/t/failure-to-send-binary-data-greather-than-64kb-using-requests/31647/5 "2022-04-12T13:43:03Z")

</div>

Since this post it seems that someone has found a fix for this in the link:  
[https://bugs.jython.org/issue2618](https://bugs.jython.org/issue2618)  
If I wanted to try to implement this fix by updating \_socket.py would I be able to do so? What would I need to watch out for?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 12, 2022, 3:27pm UTC](https://forum.inductiveautomation.com/t/failure-to-send-binary-data-greather-than-64kb-using-requests/31647/6 "2022-04-12T15:27:05Z")

</div>

Sure, you should be able to freely modify the file. I don’t think there are any ‘gotchas’.

---

<div class="post-metadata">

**Author:** ![m.sanders](https://avatars.discourse-cdn.com/v4/letter/m/df705f/32.png) [@m.sanders](https://forum.inductiveautomation.com/u/m.sanders)\
**Post date:** [April 12, 2022, 8:05pm UTC](https://forum.inductiveautomation.com/t/failure-to-send-binary-data-greather-than-64kb-using-requests/31647/7 "2022-04-12T20:05:35Z")

</div>

Worked perfectly, I am now able to send multipart/form-data from python requests with files greater than 64KB!
