问题
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