I
I
Igor Vasilevsky2015-06-03 23:58:49
Python
Igor Vasilevsky, 2015-06-03 23:58:49

Python, getting started, what to do with encoding?

Started learning Phyton, installed the latest version (tried using pycharm). Everything is clear with the basic examples, I got to the API, I decided to try with vk.com I want to do an elementary thing - Just display the user's First and Last name, specifying the ID. He doesn’t write to me in Russian letters, I get the following error:

Traceback (most recent call last):
  File "C:/...../testvk.py", line 9, in <module>
    print(test)
  File "C:\Python34\lib\encodings\cp1251.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u039f' in position 0: character maps to <undefined>

Here is an example code:
# -*- coding: utf-8 -*-
import vk
vkapi = vk.API('ID', 'mail', 'Password')
vkapi.access_token = 'token'
profiles = vkapi.users.get(user_id=298845747)
test = (profiles[0]['first_name']+' '+profiles[0]['last_name'])
print(test)

It is clear that I use the correct data (ID, mail, password)
Tell me what I'm doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
throughtheether, 2015-06-04
@goshavis

He does not write to me in Russian letters,
The problematic letter is not Russian, but Greek .
Tell me what I'm doing wrong?
Print characters to the console that it does not support. Here are some solutions to the problem. But I recommend that you use other options for displaying information (ie writing to a file or displaying it on a web page).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question