Why does venue telepot isn't correct?

一世执手 提交于 2021-01-29 12:59:01

问题


I'm trying to do a bot which could get your street name by telpot. I've inserted location in line 22 (location) and it works. But when i want to try with 'venue' it doesnt work. Can someone help me to get the name street (or venue) of my users?

import json
import time
from pprint import pprint
import telepot
from telepot.loop import MessageLoop
import telepot.namedtuple
bot = telepot.Bot(token)
lista = ["New York","Los Angeles","Miami","Toronto","Berlin","Rome","Ciao"]
seq = iter(lista)
reqloc = keyboard = {"text": "Utilizza la geolocalizzazione", "request_location": True}
keyboard = {"keyboard": [[reqloc]]+[[{"text": i} for i in pair] for pair in zip(seq)]}



def handle(msg):
    content_type, chat_type, chat_id = telepot.glance(msg)
    print(content_type, chat_type, chat_id)
    if content_type == "text":
        bot.sendMessage(chat_id, msg["text"], reply_markup=keyboard)
    if content_type == "location":
        if content_type == 'location':
      print(msg['location'])
      print(msg['location']['latitude'])
      print(msg['location']['longitude'])
      print(msg['venue']['title']]) #here is the error









MessageLoop(bot, handle).run_as_thread()
while 1:
    time.sleep(10)

Output: text private 323090362
location private 323090362
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/telepot/loop.py", line 37, in run_forever
    self._handle(msg)
  File "telegram.py", line 21, in handle
    if content_type == 'location':
KeyError: 'venue'

来源:https://stackoverflow.com/questions/61304087/why-does-venue-telepot-isnt-correct

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!