# Socket send must be binary in Jython 2.7.3 (Ignition 8.1.35 and after)

**URL:** <https://forum.inductiveautomation.com/t/socket-send-must-be-binary-in-jython-2-7-3-ignition-8-1-35-and-after/85597>\
**Category:** Ignition\
**Created:** [February 12, 2024, 11:03pm UTC](https://forum.inductiveautomation.com/t/socket-send-must-be-binary-in-jython-2-7-3-ignition-8-1-35-and-after/85597 "2024-02-12T23:03:44Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ken.maze](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ken.maze/32/85876_2.png) [@ken.maze](https://forum.inductiveautomation.com/u/ken.maze)\
**Post date:** [February 12, 2024, 11:03pm UTC](https://forum.inductiveautomation.com/t/socket-send-must-be-binary-in-jython-2-7-3-ignition-8-1-35-and-after/85597/1 "2024-02-12T23:03:44Z")

</div>

I am prepping to upgrade a couple of systems from 8.1.19 to 8.1.37. Printing to Zebra printers has been giving me fits, getting an error message like:

> TypeError: cannot make memory view because object does not have the buffer interface

I have a few places where I was writing strings to a socket and it accepted them before in 2.7.2 version Jython, but in 2.7.3 it gives the above error.

I sprinkle a few .encode("utf-8") s in to make it work.

So probably 2.7.3 is more strict about taking only binary. I don't think this is a bug, just wanted to put it on here to save the next person some time, cause it took a little while for me to hunt that down.

Here is more of the error:

> "C:\Users\kmaze.ignition\cache\gwusatizwkit3001.na.bpww.org\_8080\C0\pylib\_socket.py", line 1461, in meth  
> return getattr(self.\_sock,name)(\*args)  
> File "C:\Users\kmaze.ignition\cache\gwusatizwkit3001.na.bpww.org\_8080\C0\pylib\_socket.py", line 0, in sendall  
> TypeError: cannot make memory view because object does not have the buffer interface

Thanks

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 12, 2024, 11:36pm UTC](https://forum.inductiveautomation.com/t/socket-send-must-be-binary-in-jython-2-7-3-ignition-8-1-35-and-after/85597/2 "2024-02-12T23:36:19Z")

</div>

Or, better, just don't use jython's sockets. Python 2.7's poor separation between strings and byte arrays, which jython has to work around, makes a mess of socket interfaces. Just learn to use use the `java.net` and/or `java.nio`. Really.

---

<div class="post-metadata">

**Author:** ![Joel\_Farley](https://avatars.discourse-cdn.com/v4/letter/j/f08c70/32.png) [@Joel\_Farley](https://forum.inductiveautomation.com/u/Joel_Farley)\
**Post date:** [April 29, 2024, 3:34am UTC](https://forum.inductiveautomation.com/t/socket-send-must-be-binary-in-jython-2-7-3-ignition-8-1-35-and-after/85597/3 "2024-04-29T03:34:16Z")

</div>

Thanks for this post, Ken. Made my troubleshooting a bit easier.

I had a similar issue after updating from v8.1.35 to v8.1.39 on the weekend. What I find strange about that though, is that Jython 2.7.3 was in v8.1.34 and I wasn't having these errors. Is anyone smarter than me able to shed light on why I only now had this?

---

<div class="post-metadata">

**Author:** ![ken.maze](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ken.maze/32/85876_2.png) [@ken.maze](https://forum.inductiveautomation.com/u/ken.maze)\
**Post date:** [June 27, 2024, 3:03pm UTC](https://forum.inductiveautomation.com/t/socket-send-must-be-binary-in-jython-2-7-3-ignition-8-1-35-and-after/85597/4 "2024-06-27T15:03:24Z")

</div>

The release notes for 8.1.35 state Jython was upgraded. But I don't know why you wouldn't have encountered the problem in 8.1.35 then

---

<div class="post-metadata">

**Author:** ![Mitchell\_Maziarz](https://avatars.discourse-cdn.com/v4/letter/m/6f9a4e/32.png) [@Mitchell\_Maziarz](https://forum.inductiveautomation.com/u/Mitchell_Maziarz)\
**Post date:** [July 18, 2024, 1:05pm UTC](https://forum.inductiveautomation.com/t/socket-send-must-be-binary-in-jython-2-7-3-ignition-8-1-35-and-after/85597/5 "2024-07-18T13:05:33Z")

</div>

Just saved me hours of bashing my head against the wall

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 18, 2024, 1:36pm UTC](https://forum.inductiveautomation.com/t/socket-send-must-be-binary-in-jython-2-7-3-ignition-8-1-35-and-after/85597/6 "2024-07-18T13:36:02Z")

</div>

To avoid future misery:

> [@pturmel](#):
>
> Or, better, just don't use jython's sockets.

Really.

---

<div class="post-metadata">

**Author:** ![Mitchell\_Maziarz](https://avatars.discourse-cdn.com/v4/letter/m/6f9a4e/32.png) [@Mitchell\_Maziarz](https://forum.inductiveautomation.com/u/Mitchell_Maziarz)\
**Post date:** [July 18, 2024, 1:55pm UTC](https://forum.inductiveautomation.com/t/socket-send-must-be-binary-in-jython-2-7-3-ignition-8-1-35-and-after/85597/7 "2024-07-18T13:55:36Z")

</div>

In my defense I was just trying to patch up someone else's code to get it back working. And don't really have much experience with socket communication and what it entails. I'm just a hack

---

<div class="post-metadata">

**Author:** ![ken.maze](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ken.maze/32/85876_2.png) [@ken.maze](https://forum.inductiveautomation.com/u/ken.maze)\
**Post date:** [July 22, 2024, 4:06pm UTC](https://forum.inductiveautomation.com/t/socket-send-must-be-binary-in-jython-2-7-3-ignition-8-1-35-and-after/85597/8 "2024-07-22T16:06:06Z")

</div>

I would be glad to do that but there is no training for this that I see in the Inductive system, and I don't see a lot about it generally when I do some searching. Do you have a good source for training on this?

Thanks

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 22, 2024, 4:11pm UTC](https://forum.inductiveautomation.com/t/socket-send-must-be-binary-in-jython-2-7-3-ignition-8-1-35-and-after/85597/9 "2024-07-22T16:11:48Z")

</div>

Use java training materials, not python training materials.

And there are numerous topics here:

[https://forum.inductiveautomation.com/search?q=java.net.Socket%20order%3Alatest](https://forum.inductiveautomation.com/search?q=java.net.Socket%20order%3Alatest)

---

<div class="post-metadata">

**Author:** ![cmaynes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmaynes/32/6852_2.png) [@cmaynes](https://forum.inductiveautomation.com/u/cmaynes)\
**Post date:** [September 30, 2025, 7:45pm UTC](https://forum.inductiveautomation.com/t/socket-send-must-be-binary-in-jython-2-7-3-ignition-8-1-35-and-after/85597/10 "2025-09-30T19:45:43Z")

</div>

Hack to patch \_socket.py to convert from java.lang.String to python str. Seems to work (in my very limited testing for file upload/download and cwd). Just a stop gap for codebase making heavy use of ftplib.

Call the following before using ftplib. Should be idempotent and safe to repeatedly call.

```python
def patch_socket():	
	if not getattr(_socket._realsocket, ' __send_patched__', False):
		def _realsocket_send(self, data, *args, **kwargs):
			if isinstance(data, (String, unicode)):
				data = str(data)
			return _old_realsocket_send(self, data, *args, **kwargs)
		
		_old_realsocket_send = _socket._realsocket.send
		_socket._realsocket.send = _realsocket_send
		_socket._realsocket. __send_patched__ = True
	
	if not getattr(_socket._realsocket, ' __sendall_patched__', False):
		def _realsocket_sendall(self, data, *args, **kwargs):
			if isinstance(data, (String, unicode)):
				data = str(data)
			return _old_realsocket_sendall(self, data, *args, **kwargs)
		
		_old_realsocket_sendall = _socket._realsocket.sendall
		_socket._realsocket.sendall = _realsocket_sendall
		_socket._realsocket. __sendall_patched__ = True
	
	if not getattr(_socket.ChildSocket, ' __sendall_patched__', False):
		def _ChildSocket_sendall(self, data, *args, **kwargs):
			if isinstance(data, (String, unicode)):
				data = str(data)
			return _old_ChildSocket_sendall(self, data, *args, **kwargs)
		
		_old_ChildSocket_sendall = _socket.ChildSocket.sendall
		_socket.ChildSocket.sendall = _ChildSocket_sendall
		_socket.ChildSocket. __sendall_patched__ = True

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 30, 2025, 8:24pm UTC](https://forum.inductiveautomation.com/t/socket-send-must-be-binary-in-jython-2-7-3-ignition-8-1-35-and-after/85597/11 "2025-09-30T20:24:47Z")

</div>

> [@cmaynes](#):
>
> Hack to patch \_socket.py

I strongly recommend you **not** do this. Reread comment #9.
