# Unicode from Variable

**URL:** <https://forum.inductiveautomation.com/t/unicode-from-variable/62507>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [July 30, 2022, 2:29pm UTC](https://forum.inductiveautomation.com/t/unicode-from-variable/62507 "2022-07-30T14:29:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AGDC04](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/agdc04/32/6366_2.png) [@AGDC04](https://forum.inductiveautomation.com/u/AGDC04)\
**Post date:** [July 30, 2022, 2:29pm UTC](https://forum.inductiveautomation.com/t/unicode-from-variable/62507/1 "2022-07-30T14:29:23Z")

</div>

Hello Folks,

I’m trying to get some data from a web server, and get this data on perspective. But during the testes some data are in unicode formated with scape \u, I tried some ways to show the “right” text but no success, follow the example:

```auto
value = 'Folder Name: 8. Manuten\u00e7\u00e3o'
type(value)
print value
value2 = unicode(value,'utf-8')
type(value2)
print value2 #No Work

print u'Folder Name: 8. Manuten\u00e7\u00e3o' #Works OK

```

I I type directly on print the string with u’ works normal, but if try the same with a variable not work.

Anyone have a idea how to fix this issue?

Thanks in Advance!

---

<div class="post-metadata">

**Author:** ![cesrom](https://avatars.discourse-cdn.com/v4/letter/c/ea666f/32.png) [@cesrom](https://forum.inductiveautomation.com/u/cesrom)\
**Post date:** [July 30, 2022, 3:30pm UTC](https://forum.inductiveautomation.com/t/unicode-from-variable/62507/2 "2022-07-30T15:30:02Z")

</div>

A simple import from ` __future__ ` will fix your problem.

```python
from __future__ import unicode_literals

value = 'Folder Name: 8. Manuten\u00e7\u00e3o'
type(value)
print value
value2 = unicode(value,'utf-8')
type(value2)
print value2 

```

Will produce the following output:

```auto
>>> 
<type 'unicode'>
Folder Name: 8. Manutenção
<type 'unicode'>
Folder Name: 8. Manutenção

```

---

<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 30, 2022, 10:12pm UTC](https://forum.inductiveautomation.com/t/unicode-from-variable/62507/3 "2022-07-30T22:12:09Z")

</div>

Your first line should be:

```auto
value = u'Folder Name: 8. Manuten\u00e7\u00e3o'

```

Or use the ` __future__ ` import to always get unicode. The problem is that you must start with unicode. Once in a classic `str()`, you’ve already broken your chance to interpret the unicode correctly. You can’t do it after the fact.

So, if you are pulling from a web API, you must use methods that interpret UTF-8 as the data arrives. Please show the rest of your code, and explain the data flow more completely.

---

<div class="post-metadata">

**Author:** ![AGDC04](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/agdc04/32/6366_2.png) [@AGDC04](https://forum.inductiveautomation.com/u/AGDC04)\
**Post date:** [August 2, 2022, 9:58am UTC](https://forum.inductiveautomation.com/t/unicode-from-variable/62507/4 "2022-08-02T09:58:06Z")

</div>

Thanks for the quick response guys.

I getting data from Microsoft Graph, to get DriveItens from specific Drive, They will return a Json with the information from the Sub Folder of a Document Library at SharePoint, and the information of Files in Root of drive

```auto
def getItensOnDriveItem(SiteID, DriveID, Path):
	import httplib, urllib, system, ast, shared.HTTP.SharePointV2
	token_expired = system.tag.readBlocking(['[default]SharePointApp/Token/token_expired])
	if token_expired:
		access_token = shared.HTTP.SharePointV2.GetToken()
	else:
		access_token = system.tag.readBlocking(['[default]SharePointApp/Token/access_token'])
		
	url = "/v1.0/sites/" + SiteID + "/drives/" + DriveID + "/root:/"+ Path + ":/children"
	conn = httplib.HTTPSConnection("graph.microsoft.com")
	payload = ''
	headers = {
	  'Authorization': 'Bearer ' + access_token
	}
	conn.request("GET", url, payload, headers)
	res = conn.getresponse()
	data = res.read()
	
	return (ast.literal_eval(data.decode('utf-8')))

```

after cheking the reply from you guys, I found the issue, in the previous code I’m using the ast to convert JSON to Dict.

I replaced the code to use Json.Loads, and the Unicode are working fine now, if this code:

```auto
def getItensOnDriveItem(SiteID, DriveID, Path):
	import httplib, urllib, system, json, shared.HTTP.SharePointV2
	token_expired = system.tag.readBlocking(['[default]SharePointApp/Token/token_expired'])
	if token_expired:
		access_token = shared.HTTP.SharePointV2.GetToken()
	else:
		access_token = system.tag.readBlocking(['[default]SharePointApp/Token/access_token'])
		
	url = "/v1.0/sites/" + SiteID + "/drives/" + DriveID + "/root:/"+ Path + ":/children"
	conn = httplib.HTTPSConnection("graph.microsoft.com")
	payload = ''
	headers = {
	  'Authorization': 'Bearer ' + access_token
	}
	conn.request("GET", url, payload, headers)
	res = conn.getresponse()
	data = res.read()
	
	return (json.loads(data.decode('utf-8')))

```

---

<div class="post-metadata">

**Author:** ![Andy\_Klempau](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@Andy\_Klempau](https://forum.inductiveautomation.com/u/Andy_Klempau)\
**Post date:** [February 16, 2023, 11:26pm UTC](https://forum.inductiveautomation.com/t/unicode-from-variable/62507/5 "2023-02-16T23:26:39Z")

</div>

I am new and do not see how to post a new question, so I will continue from this related topic. I am using Ignition 8.1.24.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/d/ed0b695f3918e006866615dd9de67ff873b3b124.png)  
In the Expression Binding I can't enter unicode with a "u" prefix. Instead, I must hunt on the web for the rendered unicode, copy it, and paste into the Expression Binding text area.  
#1 How do I enter raw unicode?  
I found a degree symbol and it works in my project's Label. However, when I inherit that project into a parent project, the symbol has an "A" with a hat above it before the degree symbol. Why did that happen?  
#2 How do I get inherited projects to display the exact same unicode?
