# UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 7-9: invalid data

**URL:** <https://forum.inductiveautomation.com/t/unicodedecodeerror-utf-8-codec-cant-decode-bytes-in-position-7-9-invalid-data/19900>\
**Category:** Ignition\
**Created:** [October 1, 2018, 6:14am UTC](https://forum.inductiveautomation.com/t/unicodedecodeerror-utf-8-codec-cant-decode-bytes-in-position-7-9-invalid-data/19900 "2018-10-01T06:14:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![StefanGronberg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/stefangronberg/32/6288_2.png) [@StefanGronberg](https://forum.inductiveautomation.com/u/StefanGronberg)\
**Post date:** [October 1, 2018, 6:14am UTC](https://forum.inductiveautomation.com/t/unicodedecodeerror-utf-8-codec-cant-decode-bytes-in-position-7-9-invalid-data/19900/1 "2018-10-01T06:14:40Z")

</div>

Hi, i have this timer that runs in a template (navigation).  
When i left work on friday, i had no problems with this code line

`event.source.parent.getComponent('lblTime').text = "<HTML>" + now.strftime("%A %Y-%m-%d %H:%M:%S") + "<BR>Anv&auml;ndare: " + user.get(user.FirstName) + " " + user.get(user.LastName)`

But today i get this error when the script has not changed since friday.

```auto
Traceback (most recent call last):
  File "<event:actionPerformed>", line 9, in <module>
  File "C:\Users\sg5551\.ignition\cache\gwlocalhost_8088_8043_main\C1\pylib\encodings\utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 7-9: invalid data

	at org.python.core.codecs.strict_errors(codecs.java:227)
	at sun.reflect.GeneratedMethodAccessor76.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.python.core.JavaFunc. __call__ (Py.java:2128)
	at org.python.core.PyObject. __call__ (PyObject.java:357)
	at org.python.core.codecs.decoding_error(codecs.java:1264)
	at org.python.core.codecs.insertReplacementAndGetResume(codecs.java:1240)
	at org.python.core.codecs.PyUnicode_DecodeUTF8Stateful(codecs.java:756)
	at org.python.modules._codecs.utf_8_decode(_codecs.java:72)
	at sun.reflect.GeneratedMethodAccessor74.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:186)
	at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:204)
	at org.python.core.PyObject. __call__ (PyObject.java:422)
	at org.python.core.PyObject. __call__ (PyObject.java:426)
	at encodings.utf_8$py.decode$1(C:\Users\sg5551\.ignition\cache\gwlocalhost_8088_8043_main\C1\pylib\encodings\utf_8.py:16)
	at encodings.utf_8$py.call_function(C:\Users\sg5551\.ignition\cache\gwlocalhost_8088_8043_main\C1\pylib\encodings\utf_8.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:127)
	at org.python.core.PyFunction. __call__ (PyFunction.java:317)
	at org.python.core.PyFunction. __call__ (PyFunction.java:312)
	at org.python.core.codecs.decode(codecs.java:156)
	at org.python.core.PyString.str_decode(PyString.java:2475)
	at org.python.core.PyString.decode(PyString.java:2462)
	at org.python.core.PyString.str ___add__ (PyString.java:722)
	at org.python.core.PyString. __add__ (PyString.java:716)
	at org.python.core.PyObject._basic_add(PyObject.java:2009)
	at org.python.core.PyObject._add(PyObject.java:1995)
	at org.python.pycode._pyx15.f$0(<event:actionPerformed>:9)
	at org.python.pycode._pyx15.call_function(<event:actionPerformed>)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1275)
	at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:623)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:168)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:265)
	at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:55)
	at com.sun.proxy.$Proxy25.actionPerformed(Unknown Source)
	at com.inductiveautomation.factorypmi.application.components.PMITimer.fireActionEvent(PMITimer.java:110)
	at com.inductiveautomation.factorypmi.application.components.PMITimer.actionPerformed(PMITimer.java:124)
	at javax.swing.Timer.fireActionPerformed(Unknown Source)
	at javax.swing.Timer$DoPostEvent.run(Unknown Source)
	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$500(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

Ignition v7.8.2 (b2016030813)
Java: Oracle Corporation 1.8.0_181

```

I figured out that the problem is around this part  
`"<BR>Anv&auml;ndare: " + user.get(user.FirstName)`

This script has not been changed since 2016 and been working all the time except after this weeked.

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [October 1, 2018, 11:31am UTC](https://forum.inductiveautomation.com/t/unicodedecodeerror-utf-8-codec-cant-decode-bytes-in-position-7-9-invalid-data/19900/2 "2018-10-01T11:31:07Z")

</div>

Could you try this?

```auto
event.source.parent.getComponent('lblTime').text = "<HTML>" + now.strftime("%A %Y-%m-%d %H:%M:%S") + u"<BR>Användare: " + user.get(user.FirstName) + " " + user.get(user.LastName)

```

Notice the “u” before the string, which makes it a unicode string.

---

<div class="post-metadata">

**Author:** ![StefanGronberg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/stefangronberg/32/6288_2.png) [@StefanGronberg](https://forum.inductiveautomation.com/u/StefanGronberg)\
**Post date:** [October 1, 2018, 11:32am UTC](https://forum.inductiveautomation.com/t/unicodedecodeerror-utf-8-codec-cant-decode-bytes-in-position-7-9-invalid-data/19900/3 "2018-10-01T11:32:29Z")

</div>

Hi.  
I have already tried that, same error.  
But i figure out that the & had to be replaced with a new &, and then the error vanished, really wierd.
