Nekmo / telegram-upload

Upload and download files from Telegram up to 4 GiB using your account
MIT License
1.07k stars 233 forks source link

Fail to upload to private channel #144

Closed Ynjxsjmh closed 2 years ago

Ynjxsjmh commented 2 years ago

I tried to upload all files in folder to a private channel, but failed:

telegram-upload ./books --to <to> --directories recursive

<to> values I tried are:

but all these commands failed with ValueError: Cannot find any entity

Traceback (most recent call last):
  File "~/.local/bin/telegram-upload", line 11, in <module>
    sys.exit(upload_cli())
  File "~/.local/lib/python3.6/site-packages/telegram_upload/exceptions.py", line 50, in wrap
    return fn(*args, **kwargs)
  File "~/.local/lib/python3.6/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "~/.local/lib/python3.6/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "~/.local/lib/python3.6/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "~/.local/lib/python3.6/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "~/.local/lib/python3.6/site-packages/telegram_upload/management.py", line 101, in upload
    client.send_files(to, files, delete_on_success, print_file_id, force_file, forward, caption, thumbnail)
  File "~/.local/lib/python3.6/site-packages/telegram_upload/client.py", line 142, in send_files
    progress_callback=progress, attributes=attributes)
  File "~/.local/lib/python3.6/site-packages/telethon/sync.py", line 39, in syncified
    return loop.run_until_complete(coro)
  File "/usr/lib/python3.6/asyncio/base_events.py", line 484, in run_until_complete
    return future.result()
  File "~/.local/lib/python3.6/site-packages/telethon/client/uploads.py", line 346, in send_file
    entity = await self.get_input_entity(entity)
  File "~/.local/lib/python3.6/site-packages/telethon/client/users.py", line 437, in get_input_entity
    await self._get_entity_from_string(peer))
  File "~/.local/lib/python3.6/site-packages/telethon/client/users.py", line 575, in _get_entity_from_string
    'Cannot find any entity corresponding to "{}"'.format(string)
ValueError: Cannot find any entity corresponding to <to>

If I didn't specify the --to <to> part, it works fine.

tapatianbeast commented 2 years ago

Same here

Ynjxsjmh commented 2 years ago

@tapatianbeast I think this is a more telethon bug than telegram-upload bug after using telethon to post message to private channel. I bypass this error by changing the private channel to public temporarily because I only need to upload files to private channel one time.

doublep21 commented 2 years ago

easy fix that can be implemented :

if forward.isdigit():
        forward = PeerChannel(int(forward))

forward is called entity in telegram upload with this you can use the id for a private channel without make it public

hxse commented 2 years ago

@doublep21 Which file is this fixed in?