@778

Выдает ошибку на key как исправить?

Ошибка
File "C:\Users\scorpio\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 622, in polling
logger_level=logger_level, allowed_updates=allowed_updates)
File "C:\Users\scorpio\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 695, in __threaded_polling
raise e
File "C:\Users\scorpio\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 651, in __threaded_polling
self.worker_pool.raise_exceptions()
File "C:\Users\scorpio\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\util.py", line 147, in raise_exceptions
raise self.exception_info
File "C:\Users\scorpio\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\util.py", line 93, in run
task(*args, **kwargs)
File "F:\Python TG bot\Telegram qqw\проба команд эхо.py", line 14, in get_text_messages
bot.send_message(message.from_user.id, key,": ", pers[key])
File "C:\Users\scorpio\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\__init__.py", line 1009, in send_message
entities, allow_sending_without_reply, protect_content=protect_content))
File "C:\Users\scorpio\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\apihelper.py", line 262, in send_message
payload['entities'] = json.dumps(types.MessageEntity.to_list_of_dicts(entities))
File "C:\Users\scorpio\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\types.py", line 670, in to_list_of_dicts
res.append(MessageEntity.to_dict(e))
File "C:\Users\scorpio\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telebot\types.py", line 693, in to_dict
return {"type": self.type,
AttributeError: 'str' object has no attribute 'type'
>>>


import telebot , time
from telebot import types
from requests import get
import random
bot = telebot.TeleBot('Token')
pers = {"имя":"Неизвестно", "возраст":"Неизвестно","цвет глаз":"Неизвестно","любимое животное":"Неизвестно","хобби":"Неизвестно","О себе":"Неизвестно",}

#bot.send_message(message.from_user.id,

@bot.message_handler(content_types=['text'])
def get_text_messages(message):
global a
for key in pers:
bot.send_message(message.from_user.id, key,": ", pers[key])
bot.send_message(message.from_user.id, 'Что будем менять')
#менять имя
if (message.text == 'имя'):
bot.send_message(message.from_user.id, "введите новое имя")
pers["имя"] = a
bot.send_message(message.from_user.id, pers['имя'])
#менять возраст
if (message.text == "возраст"):
bot.send_message(message.from_user.id, "введите новый возраст")
pers["возраст"] = a
bot.send_message(message.from_user.id, pers['возраст'])
bot.polling(none_stop=True, interval=0)
  • Вопрос задан
  • 86 просмотров
Пригласить эксперта
Ответы на вопрос 1
elchako
@elchako
Python разработчик
Не правильно перебираешь ключи словаря в 13 строке
for key in pers:

Надо так
for key in pers.keys():
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы