# Utf-8 codec can't decode byte 0x81

**URL:** <https://forum.inductiveautomation.com/t/utf-8-codec-cant-decode-byte-0x81/53960>\
**Category:** Ignition\
**Tags:** ignition79, scripting\
**Created:** [December 9, 2021, 7:13pm UTC](https://forum.inductiveautomation.com/t/utf-8-codec-cant-decode-byte-0x81/53960 "2021-12-09T19:13:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![boster281](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@boster281](https://forum.inductiveautomation.com/u/boster281)\
**Post date:** [December 9, 2021, 7:13pm UTC](https://forum.inductiveautomation.com/t/utf-8-codec-cant-decode-byte-0x81/53960/1 "2021-12-09T19:13:34Z")

</div>

I am trying to send font commands to a Videojet printer using scripts.  
It works up until I try to send a Data Font command.

Here is the script as it worked before using a single line print

```
	#Select the 5x HQ dual Line Matrix for use when creating a message
	command = "1B".decode('hex') + "04".decode('hex') + "05".decode('hex')
	#Create Message to print
	message = line1 + TAB + line2 + CRETURN
	command = command + message + CRETURN

	reply = socketReqWithReply(host,command)
	reply = reply.encode('hex')
	return reply

```

Now what I am trying that is failing. I believe it is due to the “81”.decode(‘hex’) portion as if I change that number it stops giving me the error

```
	#Select the 7x9 Tri Line Matrix for use when creating a message
	command = "1B".decode('hex') + "04".decode('hex') + "07".decode('hex')
	command2 = "1B".decode('hex') + '81'.decode('hex') + "20".decode('hex')
	command3 = "1B".decode('hex') + '81'.decode('hex') + "20".decode('hex')

	
	command = command + command2 + line1 + TAB + command3 + line2 + CRETURN

	reply = socketReqWithReply(host,command)
	reply = reply.encode('hex')

```

The error I get  
return codecs.utf\_8\_decode(input, errors, True)  
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0x81 in position 4: unexpected code byte

---

<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:** [December 9, 2021, 7:29pm UTC](https://forum.inductiveautomation.com/t/utf-8-codec-cant-decode-byte-0x81/53960/2 "2021-12-09T19:29:29Z")

</div>

0x81 is not valid in utf-8. You are trying to use characters as bytes, and that is not reliable in python2 or jython. Use jython’s jarray module to create actual byte arrays, and use java networking instead of python’s socket (to not re-corrupt the bytes).

---

<div class="post-metadata">

**Author:** ![boster281](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@boster281](https://forum.inductiveautomation.com/u/boster281)\
**Post date:** [December 9, 2021, 9:49pm UTC](https://forum.inductiveautomation.com/t/utf-8-codec-cant-decode-byte-0x81/53960/3 "2021-12-09T21:49:29Z")

</div>

I found a link to [jarray module](https://www.jython.org/jython-old-sites/archive/21/docs/jarray.html) but how would I format the command [1B][81][20] in the array?

And where would I find good documentation on java networking?

---

<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:** [December 9, 2021, 10:35pm UTC](https://forum.inductiveautomation.com/t/utf-8-codec-cant-decode-byte-0x81/53960/4 "2021-12-09T22:35:47Z")

</div>

```auto
# Java bytes are signed, so bias anything >=0x80 by 256
cmd = jarray.array([0x1b, 0x81-256, 0x20], 'b')

```

> [@boster281](#):
>
> good documentation

Heh. Stack exchange? Or just search this forum for `java.net` and/or `java.nio`.
