Форум сайта python.su
Всем добрый вечер.
Решил использовать Telethon для отправки боту своей геолокации
Но не получилось пока
в этом виде данные не проходят
сообщение отправляется а геолокация не хочет в этом виде
Подскажите, чего я не так делаю.
from telethon import TelegramClient, events, sync from telethon.tl.functions.contacts import ResolveUsernameRequest from telethon.tl.types import InputChannelEmpty from telethon import TelegramClient from telethon.tl.types.messages import Messages from telethon.tl.types.contacts import Contacts from telethon.tl.custom import Button from telethon.tl.functions.messages import SendMessageRequest #telethon.utils.get_input_geo # These example values won't work. You must get your own api_id and # api_hash from https://my.telegram.org, under API Development. api_id = 12345 api_hash = '0123456789abcdef0123456789abcdef' client = TelegramClient('pointik', api_id, api_hash) client.start() client.send_message('name', 'msg') result = client.inline_query('@bot', 'query', offset = None, geo_point= (30.379251039815593, 59.80547555591638, 8726921181762874873))
python3.5/site-packages/telethon/tl/functions/messages.py", line 1506, in __bytes__ b'' if self.geo_point is None or self.geo_point is False else (bytes(self.geo_point)), TypeError: 'float' object cannot be interpreted as an integer
Отредактировано Kasta_neda (Ноя. 24, 2018 22:02:25)
Офлайн
Попробуй
geo_point=(30.379251039815593, 59.80547555591638)
Офлайн
py.user.nextУже много чего перепробовал, не принимает
Попробуй
geo_point=( int(round(30.379251039815593, 3)), int(round(59.80547555591638, 3)), (8726921181762874873))
python3.5/site-packages/telethon/tl/functions/messages.py", line 1506, in __bytes__ b'' if self.geo_point is None or self.geo_point is False else (bytes(self.geo_point)), ValueError: bytes must be in range(0, 256)
geo_point=( int(round(30.379251039815593, 3)), int(round(59.80547555591638, 3)))
python3.5/asyncio/futures.py", line 293, in result raise self._exception telethon.errors.rpcerrorlist.InputConstructorInvalidError: The provided constructor is invalid (caused by GetInlineBotResultsRequest)
class telethon.client.bots.BotMethods(session, api_id, api_hash, *, connection=<class
’telethon.network.connection.tcpfull.ConnectionTcpFull’>,
use_ipv6=False, proxy=None, timeout=10,
request_retries=5, connection_retries=5,
retry_delay=1, auto_reconnect=True, sequential_updates=False,
flood_sleep_threshold=60,
device_model=None, system_version=None,
app_version=None, lang_code=’en’, system_lang_code=’en’,
loop=None)
Bases: telethon.client.users.UserMethods
inline_query(bot, query, *, offset=None, geo_point=None)
Makes the given inline query to the specified bot i.e. @vote My New Poll would be as follows:
>>> client = …
>>> client.inline_query('vote', ‘My New Poll’)
Args:
bot (entity): The bot entity to which the inline query should be made.
query (str): The query that should be made to the bot.
offset (str, optional): The string offset to use for the bot.
geo_point (GeoPoint, optional) The geo point location information to send to the bot for localised
results. Available under some bots.
Returns: A list of custom.InlineResult.
GeoPoint
—types—
geoPoint#0296f104 long:double lat:double access_hash:long = GeoPoint
Отредактировано Kasta_neda (Ноя. 25, 2018 09:58:44)
Офлайн
С чего ты взял, что там надо передавать три значения?
Офлайн
py.user.next
GeoPoint
—types—
geoPoint#0296f104 long:double lat:double access_hash:long = GeoPoint
telethon.errors.rpcerrorlist.InputConstructorInvalidError: The provided constructor is invalid (caused by GetInlineBotResultsRequest)
Офлайн
Похоже мне не этот метод нужен, бот не принимает его.
Значит надо просто сообщением отправить, понять бы только как .
Офлайн
По идее должен так
client.send_message('name', 'Hello there!', file=InputGeoPoint(...))
from telethon.sync import TelegramClient from telethon import functions, types api_id = 132456 api_hash = 'f81672064070fc834f3b567c626e049' with TelegramClient('name', api_id, api_hash) as client: result = client(functions.messages.SendMediaRequest( peer='to', media=types.InputMediaGeoPoint( types.InputGeoPoint( lat=59.80547555591638, long=30.379251039815593 ), ), message='' )) #print(result.stringify())
Офлайн