Answer the question
In order to leave comments, you need to log in
Encoding issue when requesting VK api in Python?
I make a request for the messages.getConversations method, and an encoding error appears in the console
param = dict(access_token = 'mytoken',
version = 5.95,
count = 10
)
chat = requests.get('https://api.vk.com/method/messages.getConversations', param)
print(chat.text)
Traceback (most recent call last):
File "C:\Users\User\Desktop\main.py", line 22, in <module>
print(chat.text)
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\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 '\U0001f4cc' in position 6739: character maps to <undefined>
print(chat.text.encode("utf-8"))
Answer the question
In order to leave comments, you need to log in
encode()
must be used together with decode()
, then the console will print everything that is needed:"\U0001f4cc".encode(encoding='utf-8').decode()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question