V
V
Valery Zhmyshenko2020-09-04 18:06:28
Python
Valery Zhmyshenko, 2020-09-04 18:06:28

Encoding error in python3 UnicodeEncodeError?

UnicodeEncodeError: 'ascii' codec can't encode characters in position 21-24: ordinal not in range(128)
"

This is what crashes when the function is run.
Here is the code:
user = user_id
        my_info = vk.users.get()[0]
        my_id = my_info['id']
        my_name = my_info['first_name'] + ' ' + my_info['last_name']
        target_name = names_list[dialog_list.index(user)]

        vv = open(f'{chat_id_path}/{target_name}.txt', 'tw', encoding='utf-8')
                                vv.close()

Swears at this line
vv = open(f'{chat_id_path}/{target_name}.txt', 'tw', encoding='utf-8')

I'm running from the 3rd python.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Valery Zhmyshenko, 2020-09-05
@mcborrrov

Answer: the code is correct, but the server simply does not support UTF-8

V
Viktor T2, 2020-09-04
@Viktor_T2

have you tried encoding='cp1251'?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question