Nekmo / telegram-upload

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

Catch ChatWriteForbiddenError #84

Closed joan-carles closed 3 years ago

joan-carles commented 3 years ago
Debian testing
joan@debian:~$ pip freeze
beautifulsoup4==4.9.3
Brlapi==0.8.1
caffeine==2.9.8
catfish==1.4.13
certifi==2020.6.20
cffi==1.14.4
chardet==3.0.4
click==7.1.2
cryptg==0.2.post2
cryptography==3.2.1
cupshelpers==1.0
dbus-python==1.2.16
distro==1.5.0
ewmh==0.1.6
eyeD3==0.8.10
feedparser==5.2.1
gpodder==3.10.17
hachoir==3.1.1
html5lib==1.1
idna==2.10
louis==3.16.0
lxml==4.6.2
menulibre==2.2.1
musicbrainzngs==0.7.1
mutagen==1.45.1
mygpoclient==1.8
numpy==1.19.4
olefile==0.46
pexpect==4.6.0
Pillow==8.0.1
podcastparser==0.6.5
psutil==5.7.3
pyaes==1.6.1
pyasn1==0.4.8
pycairo==1.16.2
pycparser==2.20
pycups==2.0.1
PyGObject==3.38.0
pyinotify==0.9.6
pysmbc==1.0.23
python-apt==2.1.7
python-debian==0.1.39
python-magic==0.4.16
python-xlib==0.29
pyxattr==0.7.2
pyxdg==0.26
quodlibet==4.3.0
Recoll==1.0
recollchm==0.8.4.1+git
requests==2.24.0
rsa==4.6
simplejson==3.17.0
six==1.15.0
soupsieve==2.1
specan==0.0.0
telegram-upload==0.4.0
Telethon==1.18.2
ufw==0.36
urllib3==1.25.11
webencodings==0.5.1
youtube-dl==2020.12.29

Description

When I try to upload a file or a set of files I get next error in debian testing:

user@debian:~$ telegram-upload --to pics --force-file --directories recursive /media/DATOS/media/pics/
Uploading "me.jpg"  [####################################]  100%
Traceback (most recent call last):
  File "/usr/local/bin/telegram-upload", line 8, in <module>
    sys.exit(upload_cli())
  File "/usr/local/lib/python3.9/dist-packages/telegram_upload/exceptions.py", line 50, in wrap
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-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 "/usr/local/lib/python3.9/dist-packages/telegram_upload/client.py", line 139, in send_files
    message = self.send_file(entity, file, thumb=thumb,
  File "/usr/local/lib/python3.9/dist-packages/telethon/sync.py", line 39, in syncified
    return loop.run_until_complete(coro)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.9/dist-packages/telethon/client/uploads.py", line 372, in send_file
    return self._get_response_message(request, await self(request), entity)
  File "/usr/local/lib/python3.9/dist-packages/telethon/client/users.py", line 30, in __call__
    return await self._call(self._sender, request, ordered=ordered)
  File "/usr/local/lib/python3.9/dist-packages/telethon/client/users.py", line 79, in _call
    result = await future
telethon.errors.rpcerrorlist.ChatWriteForbiddenError: You can't write in this chat (caused by SendMediaRequest)

In the raspberry Pi I get very similar error doing the same:

pi@raspberrypi:~ $ telegram-upload --to pics --force-file --directories recursive /media/DATOS/media/pics/
Uploading "me.jpg"  [####################################]  100%
Traceback (most recent call last):
  File "/usr/local/bin/telegram-upload", line 10, in <module>
    sys.exit(upload_cli())
  File "/usr/local/lib/python3.7/dist-packages/telegram_upload/exceptions.py", line 50, in wrap
    return fn(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-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 "/usr/local/lib/python3.7/dist-packages/telegram_upload/client.py", line 142, in send_files
    progress_callback=progress, attributes=attributes)
  File "/usr/local/lib/python3.7/dist-packages/telethon/sync.py", line 39, in syncified
    return loop.run_until_complete(coro)
  File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.7/dist-packages/telethon/client/uploads.py", line 372, in send_file
    return self._get_response_message(request, await self(request), entity)
  File "/usr/local/lib/python3.7/dist-packages/telethon/client/users.py", line 30, in __call__
    return await self._call(self._sender, request, ordered=ordered)
  File "/usr/local/lib/python3.7/dist-packages/telethon/client/users.py", line 79, in _call
    result = await future
telethon.errors.rpcerrorlist.ChatWriteForbiddenError: You can't write in this chat (caused by SendMediaRequest)

What I Did

I installed the software through

sudo pip3 install -U telegram-upload

Then I went to 

https://my.telegram.org/auth

and the in API development tools I got My API id and API hash.

Then I ran the command:

telegram-upload --to pics --force-file --directories recursive /media/DATOS/media/pics/

and then introduced api_id, api-hash, phone number and code received by phone
Nekmo commented 3 years ago

@joan-carles reads the error message:

telethon.errors.rpcerrorlist.ChatWriteForbiddenError: You can't write in this chat (caused by SendMediaRequest)

However, Telegram-upload should catch this error if there are no permissions for the chat id.

joan-carles commented 3 years ago

Hi

I'm trying to upload files in a private channel. The private channel only has 1 member and this member is the administrator. And this user absolutely has all the permissions.

https://imgur.com/Xmj4tCD.png

Do I have to add another user in order upload with telegram upload?

Any solution in order to fix the problem? Right now in my case the software is completely broken.

How can I have permission for an specific chat id? I really thought that if you introduce information about api, your phone number and the access code then you should have permissions. Oww I see you are Spanish :D (Yo también)

If I miss something trivial sorry.

joan-carles commented 3 years ago

It was my mistake. Instead of invitation link to channel I used the channel name. So the software works well. Was my mistake

Thanks