Z
Z
zhmerin2020-01-17 15:17:29
Python
zhmerin, 2020-01-17 15:17:29

How to fix 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128) error?

Hello, I'm trying to run my bot on https://www.pythonanywhere.com/
But I get this error:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)
Swears at this line in bothe:

bot.edit_message_text(chat_id = c.message.chat.id, message_id = c.message.message_id, text = yourorder + u'Страна: ' + district + '\n\n' + u'Выбери товар', reply_markup=key)

ps variables yourorder and district contain Cyrillic

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Pankov, 2020-01-20
@zhmerin

yourorder = yourorder.decode('utf-8')  # или 'cp1251' или 'cp866' или что та у вас
district = district.decode('utf-8')
bot.edit_message_text(
    chat_id=c.message.chat.id,
    message_id=c.message.message_id,
    text= u'{}Страна: {}\n\nВыбери товар'.format(yourorder, district), 
    reply_markup=key,
)

You are also concatenating a unicode string with a non-unicode string ('\n\n'). Do not do it this way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question