Closed parazitt closed 5 years ago
This code works fine in the latest versions of the library.
i fixed this problem:
uploaded = clients.upload_file("/tmp/5.jpg")
media = InputMediaUploadedPhoto(uploaded)
clients.send_file("me",media)
worked fine
That should not be necessary in the latest version, but okay.
you right! but i using sync version in multi-thread script
Sync version is not supported. You can use asyncio and threads if you know how. But this is going offtopic.
Hi! I met the same problem resending messages with links:
async def main():
async for message in client.iter_messages('@some_chanel', limit=5):
try:
await client.send_message(entity='xxxxx', message=message.message, reply_to=None, file=message.media)
except NameError:
print('error: ' + str(NameError))
pass
with client:
client.loop.run_until_complete(main())
then get an error:
Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/telethon/utils.py", line 348, in get_input_media if media.SUBCLASS_OF_ID == 0xfaf846f4: # crc32(b'InputMedia') AttributeError: 'NoneType' object has no attribute 'SUBCLASS_OF_ID'
@ted24 your traceback does not correspond with the code of the latest version (thus, you have an old version installed).
thanks, but latest version doesn't allow to use file=message.media, could you please advise how to resend media without downloading it?
File "/usr/local/lib/python3.7/site-packages/telethon/client/messages.py", line 685, in send_message buttons=buttons File "/usr/local/lib/python3.7/site-packages/telethon/client/uploads.py", line 343, in send_file raise TypeError('Cannot use {!r} as file'.format(file)) TypeError: Cannot use <telethon.tl.types.MessageMediaWebPage object at 0x10e38bda0> as file
No version has ever supported file=MessageMediaWebPage(...)
, and where it crashed before, it now raises the correct error.
Hi! I'm trying to create an userbot with Telethon but I'm running into the exact same error as @parazitt.
I'm running the current latest version of Telethon (1.16.2) installed from the main branch.
I've tried both uploading first then sending and only sending the file, same outcome.
I was able to send the image a couple of times, like if I send it to myself it works but to a friend the error comes out
uploaded = await bot.upload_file(str(carbon_file))
media = InputMediaUploadedPhoto(uploaded)
await bot.send_file(event.chat, media)
# Just sending
await bot.send_file(event.chat, str(carbon_file))
Traceback (most recent call last):
File "C:\Users\MrMarble\PycharmProjects\userbot\userbot\modules\carbonsh.py", line 27, in carbon
await bot.send_file(event.chat, media)
File "C:\Users\MrMarble\PycharmProjects\userbot\venv\lib\site-packages\telethon\client\uploads.py", line 355, in send_file
entity = await self.get_input_entity(entity)
File "C:\Users\MrMarble\PycharmProjects\userbot\venv\lib\site-packages\telethon\client\users.py", line 419, in get_input_entity
peer = utils.get_peer(peer)
File "C:\Users\MrMarble\PycharmProjects\userbot\venv\lib\site-packages\telethon\utils.py", line 909, in get_peer
_raise_cast_fail(peer, 'Peer')
File "C:\Users\MrMarble\PycharmProjects\userbot\venv\lib\site-packages\telethon\utils.py", line 139, in _raise_cast_fail
type(entity).__name__, target))
TypeError: Cannot cast NoneType to any kind of Peer.
The problem is that event.chat
is None
. It has nothing to do with sending the file. The documentation states chat
may be None
, and if you're going to use it in a input parameter, event.input_chat
should be used instead.
hello Dear,
i have a problem with send file my code is: x= clients.upload_file("/tmp/5.jpg") clients.send_file("me", x)
i got:
or clients.send_message("me", "sdf", file="/tmp/5.jpg") # or clients.send_file("me", file="/tmp/5.jpg")
even when i run this: clients(SendMediaRequest("me",x,'dsf'))
how i can fix it?