Failed to read content without ASCII

I want to read non-ASCII JSON data, in my case it is in Persian, from a web page. Here is my code in python-2.7:

jsonObject = json.loads(urllib2.urlopen("https://api.instagram.com/v1/users/"+userId+"/?access_token="+accessToken).read().decode('utf-8').encode('utf-8'));
print jsonObject;

Unfortunately, even after decodingand encodingI got the result as follows:

{u'meta': {u'code': 200}, u'data': {u'username': u'*******', u'bio': u'\u0639\u06a9\u0633 \u062f\u0648 \u0646\u0641\u0631\u062a\u0648\u0646 \u0631\u0648 \u0627\u0631\u0633\u0627\u0644 \u06a9\u0646\u06cc\u062f\U0001f48f\U0001f491', u'website': u'', u'profile_picture': u'*****', u'full_name': u'\U0001f451\u0639\u0634\u0642 \u0647\u0627\u06cc \u0627\u06cc\u0631\u0627\u0646\u06cc\U0001f451', u'counts': {u'media': 31, u'followed_by': 12449, u'follows': 0}, u'id': u'*******'}}

What do I need to do to get the characters correctly?

+4
source share
1 answer

This is normal. The contents of the container use Python syntax representations that are ASCII compatible.

Print out individual string values ​​and you will see that the actual value still exists:

>>> print jsonObject['data']['bio']
عکس دو نفرتون رو ارسال کنید💏💑
+6
source

Source: https://habr.com/ru/post/1619728/


All Articles