T
T
tupoi2016-06-22 22:12:21
Python
tupoi, 2016-06-22 22:12:21

Why doesn't python display utf-8 cyrillic?

Good day to all, I decided to look at the VK API today and used python, I managed to make a request, I received an answer, but the problem is that the answer comes like this

{u'response': [{u'first_name': u'\u041f\u0430\u0432\u0435\u043b', u'last_name': u'\u0414\u0443\u0440\u043e\u0432', u'id': 1, u'bdate': u'10.10.1984'}]}

at the same time, if the names are written in Latin letters, then everything is fine, how to fix it and make it display the same Cyrillic alphabet, here is the code
# coding:utf8
import requests

req = requests.get('http://api.vk.com/method/users.get?user_ids=1&fields=bdate&v=5.52')
print (req.status_code)
result = req.json()
print result

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fixid, 2016-06-22
@tupoi

The answer comes right, in Unicode. If you really need to, you can convert to UTF8.
Python and UTF8
https://habrahabr.ru/post/135913/
In python3, all str are in Unicode by default

S
sim3x, 2016-06-23
@sim3x

The characters you write are part of the Cyrillic alphabet
The answer came to you in utf-8
Perhaps requests converted it to utf-8 ascii safe in which each character is represented as a sequence \u041f
In your case, you do not need to convert to unicode - requests will do everything by itself

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question