LonamiWebs/Telethon

RPC login error

jtonkeys1 opened this issue Β· 68 comments

telethon.errors.rpcbaseerrors.AuthKeyError: RPCError 406: UPDATE_APP_TO_LOGIN (caused by SignInRequest)

I am getting this error, anyone know the problem? Ubuntu 20.04 fresh install & can also replicate on macOS

raicg commented

I'm having the same problem, it only happens on the first access, when we are getting a code to login

I have a similar problem on Windows 11 and I can also replicate it on Ubuntu 20.04.

telethon.errors.rpcbaseerrors.AuthKeyError: RPCError 406: UPDATE_APP_TO_LOGIN (caused by SendCodeRequest)

It only appears when I try to login with phone number. But there was no problem yesterday.

telethon.errors.rpcbaseerrors.AuthKeyError: RPCError 406: UPDATE_APP_TO_LOGIN (caused by SendCodeRequest)
Here is the full traceback, on calling client.start()

File "/home/ec2-user/forwardgram/venv/lib64/python3.7/site-packages/telethon/client/auth.py", line 133, in start
    else self.loop.run_until_complete(coro)
  File "/usr/lib64/python3.7/asyncio/base_events.py", line 587, in run_until_complete
    return future.result()
  File "/home/ec2-user/forwardgram/venv/lib64/python3.7/site-packages/telethon/client/auth.py", line 189, in _start
    await self.send_code_request(phone, force_sms=force_sms)
  File "/home/ec2-user/forwardgram/venv/lib64/python3.7/site-packages/telethon/client/auth.py", line 515, in send_code_request
    phone, self.api_id, self.api_hash, types.CodeSettings()))
  File "/home/ec2-user/forwardgram/venv/lib64/python3.7/site-packages/telethon/client/users.py", line 30, in __call__
    return await self._call(self._sender, request, ordered=ordered)
  File "/home/ec2-user/forwardgram/venv/lib64/python3.7/site-packages/telethon/client/users.py", line 79, in _call
    result = await future
telethon.errors.rpcbaseerrors.AuthKeyError: RPCError 406: UPDATE_APP_TO_LOGIN (caused by SendCodeRequest)

Facing the same issue on AWS EC2, based on CentOS. This was working fine few hours ago. I got this error, when I opened up a new session, while I had 3 existing sessions already.

I have a same problem on Ubuntu 20.04

Having same issue on windows10

I have same issue
Does anyone find a solution?

The library must be updated. I will try to find time to do so as soon as possible (at least so that login works…). Previous sessions should be okay for a bit longer. Thank you all for your patience.

If you have the same issue, please react with a thumbs-up (πŸ‘) emoji to the original post rather than posting another comment to avoid notifying everyone. I will post updates in this thread.

Telegram has started enforcing the use of 64-bit identifiers for users and chats, and the current stable version of the library does not support them yet. If you try to login, you may see UPDATE_APP_TO_LOGIN error.

I will try to find time to update the library as soon as possible. Although the first version supporting this new layer may not be as well-tested as I would've liked (because I haven't had much time to devote to open source lately). Thank you for your patience.

If you want to stay updated, please subscribe to this GitHub thread.

old fix, read further comments for current solution

If someone desperatily needs this fix, please uninstall telethon and install either:

(You may also use a virtual environment.)

Here are some additional questions people have asked, and the answers:

How does Telegram know if Telethon supports 64-bit IDs or not?

Telegram has a concept known as "layers", allowing old apps to remain working on old layers, and new apps using new layers to enjoy new changes. The current stable version of Telethon has an old layer. Telegram has "split" the layers and left old ones no longer working probably because recent changes have made it very hard to remain backward-compatible (changing user identifiers from 32 to 64 bits is a pretty big change).

After the library updates will the previous session be compatible/usable or will they become invalid?

Previous session files should remain valid (Telethon will still understand them), but it's not possible to know if Telegram will revoke them for other reasons (although it shouldn't).

Does this issue affect bots too?

Yes, bots also need to "login" to work with the API, using a bot token, so they also can get the error.

If I have userbot running, until I restart, it should (probably) be okay?

Existing sessions (and sessions currently in use) should be fine.

Will Telethon add block ads?

The library will not block sponsored messages. Doing so is against Telegram's Terms of Service. If you develop an application using Telethon, you must comply with them, or risk getting your account banned in some way.

If your app allows accessing content from Telegram channels, you must include support for official sponsored messages in Telegram channels and may not interefere with this functionality.

When will a fix be published?

I will try to do this as soon as possible, but because the release will be rushed, bugs may be present. If this is the case, please be sure to report them (or vote if they already exist). For a temporary workaround, please refer to #3215 (comment).

can this be fixed today please?

Hi

Will we have to modify the codes of all our scripts using Telethon?

Thanks !

Hi

Will we have to modify the codes of all our scripts using Telethon?

Thanks !

how please?

Hi

Will we have to modify the codes of all our scripts using Telethon?

Thanks !

no, telethon will take care of compatibility. only if you made stupid assumptions like userd-id will never bigger than 2,147,483,647 you may have to change your script.

how can I add ads if I use the library as a bot for communicating with user accounts

I have pushed v1.24 to PyPi, which fixes login (thus avoiding UPDATE_APP_TO_LOGIN), but I have not had the time to test this version thoroughly, so please make sure to report any issues you find here on GitHub.

It contains two more hot-fixes (and the "latest" 133 layer, to prevent receiving broken constructors), but not the latest layer, currently 135, to avoid breaking more things than necessary). Note that if you uninstalled telethon to install the workarounds, you will now need to uninstall the workarounds and install telethon again.

Thank you for your patience and understanding.

Please be aware that this new version uses 64 bit identifier for users, chats, and more. You may need to update your code to handle this correctly.

1 - Thanks for the work @Lonami! It really helps a lot!
2 - When you release the final new version, could you alert here? So we all update immediately.
3 - About security, there was any meaningfull change?

I have pushed v1.24 to PyPi, which fixes login (thus avoiding UPDATE_APP_TO_LOGIN), but I have not had the time to test this version thoroughly, so please make sure to report any issues you find here on GitHub...

Thanks for your work!

I have pushed v1.24 to PyPi, which fixes login (thus avoiding UPDATE_APP_TO_LOGIN), but I have not had the time to test this version thoroughly, so please make sure to report any issues you find here on GitHub.

It contains two more hot-fixes (and the "latest" 133 layer, to prevent receiving broken constructors), but not the latest layer, currently 135, to avoid breaking more things than necessary). Note that if you uninstalled telethon to install the workarounds, you will now need to uninstall the workarounds and install telethon again.

Thank you for your patience and understanding.

Please be aware that this new version uses 64 bit identifier for users, chats, and more. You may need to update your code to handle this correctly.

Thanks!

Sadly does not work for me

@joaopedrolourencoaffonso yes, I can notify about future versions here (if I remember). Regarding security, I'm not sure what you're asking. There have been no security issues that I know of in the previous or current version. You can ask me privately about this if you know something.

@BramGamingNL please make sure you've successfully installed the latest version (verify that print(telethon.__version__) after importing is indeed 1.24).

Lonami has given solution, but still many folks misread.
SOLUTION:
Updated: Temporary workaround:

pip uninstall telethon
pip install tulir-telethon

or

pip3 uninstall telethon
pip3 install tulir-telethon

@graysuit that was only a temporary workaround which is no longer necessary. Updating telethon is enough (and the officially supported way to do it).

Do the new 64-bit identifiers change entity ID and HASH (for people that store them outside code or session file)?
If yes will the code break when calling old entities?
Thanks

When sending the code to the phone, there is no error, but the code does not come, what is my mistake?

@netquik since an ID never changes, old accounts will still utilize only below 32 bits for their IDs, however, accounts from new users may up to 64 bits (in reality a bit less). The access hash should not be affected for old accounts either.

@BondarenkoOleksandr this seems to not be related to this issue, please see previous issues about that topic, as I believe it's happened and been discussed before.

Yeah I dont know what you all are saying its still broken. Updating telethon has not worked and I'm already on 1.24

thanks @graysuit solved

didnt work personally

@BramGamingNL please run the following command on a terminal and make sure it's 1.24.0:

python -c "import telethon; print(telethon.__version__)"

Make sure you use the same Python binary and/or environment as you do when running Telethon.

Yeah its 1.24.0.

Please open a new issue with the full error traceback and commit you're using.

@graysuit that was only a temporary workaround which is no longer necessary. Updating telethon is enough (and the officially supported way to do it).

@Lonami Thanks.
But I didn't understand why issue isn't closed yet, if it resolved in latest telethon package ?

mabye cuz it doesnt work for everyone..... i did update&upgrade deleted old telethon and installed latest and it didnt work, not even the temporary fix

@graysuit that was only a temporary workaround which is no longer necessary. Updating telethon is enough (and the officially supported way to do it).

@Lonami Thanks. But I didn't understand why issue isn't closed yet, if it resolved in latest telethon package ?

Actually there still the whole thing with the sponsored messages plus any unseen bugs that might emerge in the next weeks.

can anyone help me with this issue? still cant solve it

Same, not going to open a new one as its the same issue kek

Same, not going to open a new one as its the same issue kek

as it's working for other's including me, more information is needed to find out why it's nor working for you
this is why lonami asking for a new issue with traceback etc.

without this you may wait forever for a solution.

Yeah i posted it

doing
pip install telethon --update
solved it for me

pip install telethon --update

no such option: --update

pip install -U telethon
(-U should be --upgrade in short and is command of install so must be used after install)
first be sure to use new version 1.2.4
you will see something like this if you use wheel
Downloading Telethon-1.24.0-py3-none-any.whl

Yeah I already did that, "already satatisfied"

Maybe you need to use --no-cache?

What does that do? it gives me '--no-cache' is not recognized as an internal or external command,
operable program or batch file.

Sorry I didn't make myself clear. It's a flag you have to add to your pip command (the one you use when upgrading Telethon).

What does that do? it gives me '--no-cache' is not recognized as an internal or external command, operable program or batch file.

@BramGamingNL not just --no-cache, but pip install -U telethon --no-cache

Yeah I already did that, "already satisfied"
@BramGamingNL
Well if your are sure to have new Telethon==1.24.0 (pip freeze) and that you are working in the same environment where you did the upgrade, you should probably explain further the errors you are getting, and more details about your code (for example if your code is requiring a specific version of telethon, if you are compiling it, or the environment of your project)

What does that do? it gives me '--no-cache' is not recognized as an internal or external command, operable program or batch file.

@BramGamingNL not just --no-cache, but pip install -U telethon --no-cache

deleted and then got this

C:\Users\Bram>pip install -U telethon --no-cache
Collecting telethon
Downloading Telethon-1.24.0-py3-none-any.whl (528 kB)
|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 528 kB 6.4 MB/s
Requirement already satisfied: rsa in c:\users\bram\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from telethon) (4.8)
Requirement already satisfied: pyaes in c:\users\bram\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from telethon) (1.6.1)
Requirement already satisfied: pyasn1>=0.1.3 in c:\users\bram\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from rsa->telethon) (0.4.8)
Installing collected packages: telethon
Successfully installed telethon-1.24.0

Does it work now?

Holy fucking shit, thank you guys for trying to help but I found the issue. I had 2 pythons installed. I deleted 3.7 and 3.10 works. Thanks dudes

I just solved this issue by: python3 -m pip install --upgrade telethon

Hi,

I got the same issue on my RPI4 with yunohost to use telegramebot with Mautrix_telegram.
I tried to uninstall + update telethon, but I still got the issue when i try ton login with my telegram account...

LOG :

Traceback (most recent call last): File "/opt/yunohost/mautrix_telegram/lib/python3.7/site-packages/mautrix/bridge/commands/handler.py", line 409, in handle await self._run_handler(handler, evt) File "/opt/yunohost/mautrix_telegram/lib/python3.7/site-packages/mautrix_telegram/commands/handler.py", line 121, in _run_handler return await handler(evt) File "/opt/yunohost/mautrix_telegram/lib/python3.7/site-packages/mautrix/bridge/commands/handler.py", line 296, in __call__ return await self._handler(evt) File "/opt/yunohost/mautrix_telegram/lib/python3.7/site-packages/mautrix_telegram/commands/telegram/auth.py", line 155, in login_qr await qr_login.recreate() File "/opt/yunohost/mautrix_telegram/lib/python3.7/site-packages/telethon/tl/custom/qrlogin.py", line 27, in recreate self._resp = await self._client(self._request) File "/opt/yunohost/mautrix_telegram/lib/python3.7/site-packages/telethon/client/users.py", line 30, in __call__ return await self._call(self._sender, request, ordered=ordered) File "/opt/yunohost/mautrix_telegram/lib/python3.7/site-packages/telethon/client/users.py", line 79, in _call result = await future telethon.errors.rpcbaseerrors.AuthKeyError: RPCError 406: UPDATE_APP_TO_LOGIN (caused by ExportLoginTokenRequest)

Did I miss something ?

More info :
python is already the newest version (2.7.16-1).
Telethon version : Telethon-1.24.0

Thx

C:\Users\Anderson>pip install -U telethon --no-cache
Requirement already satisfied: telethon in c:\users\anderson\appdata\local\programs\python\python39\lib\site-packages (1.24.0)
Requirement already satisfied: rsa in c:\users\anderson\appdata\local\programs\python\python39\lib\site-packages (from telethon) (4.8)
Requirement already satisfied: pyaes in c:\users\anderson\appdata\local\programs\python\python39\lib\site-packages (from telethon) (1.6.1)
Requirement already satisfied: pyasn1>=0.1.3 in c:\users\anderson\appdata\local\programs\python\python39\lib\site-packages (from rsa->telethon) (0.4.8)
WARNING: You are using pip version 21.1.3; however, version 21.3.1 is available.
You should consider upgrading via the 'c:\users\anderson\appdata\local\programs\python\python39\python.exe -m pip install --upgrade pip' command.

continuo com o mesmo problema poderia me ajudar, pois nao consigo logar telegram

I have the same error (406 UPDATE_APP_TO_LOGIN) in python scripts attempting to login to Telegram :( I upgraded Telethon to ver. 1.24.0 but it didn't solve the problem.
Does anybody know how to finally solve that problem, please?
Thx in advance for any tip.

I have the same error (406 UPDATE_APP_TO_LOGIN) in python scripts attempting to login to Telegram :( I upgraded Telethon to ver. 1.24.0 but it didn't solve the problem. Does anybody know how to finally solve that problem, please?

Please take care that your script is using the correct version. To verify add print the telethon version in your bot script right after the "import telethon" statement and run your script as usual, .e.g.

import telethon
print('Telethon Version used: '+telethon.__version__)
quit()

this should output:
Telethon Version used: 1.24.0

I have the same error (406 UPDATE_APP_TO_LOGIN) in python scripts attempting to login to Telegram :( I upgraded Telethon to ver. 1.24.0 but it didn't solve the problem. Does anybody know how to finally solve that problem, please?

Please take care that your script is using the correct version. To verify add print the telethon version in your bot script right after the "import telethon" statement and run your script as usual, .e.g.

import telethon
print('Telethon Version used: '+telethon.__version__)
quit()

this should output: Telethon Version used: 1.24.0

Thank you for your suggeston.
I checked it and script uses correct version. I don't know where to find the potential issue. Maybe you can look at the error result of the script and suggest something more? Here is the errors on the screen after the script run:
Pyrogram v1.2.9, Copyright (C) 2017-2021 Dan https://github.com/delivrance
Licensed under the terms of the GNU Lesser General Public License v3 or later (LGPLv3+)

Traceback (most recent call last):
File "C:\Users\me\Desktop\TS_SPECIAL\login.py", line 38, in
app.start()
File "C:\Users\me\AppData\Roaming\Python\Python310\site-packages\pyrogram\sync.py", line 57, in async_to_sync_wrap
return loop.run_until_complete(coroutine)
File "C:\Program Files\Python310\lib\asyncio\base_events.py", line 641, in run_until_complete
return future.result()
File "C:\Users\me\AppData\Roaming\Python\Python310\site-packages\pyrogram\methods\utilities\start.py", line 58, in start
await self.authorize()
File "C:\Users\me\AppData\Roaming\Python\Python310\site-packages\pyrogram\client.py", line 304, in authorize
sent_code = await self.send_code(self.phone_number)
File "C:\Users\me\AppData\Roaming\Python\Python310\site-packages\pyrogram\methods\auth\send_code.py", line 50, in send_code
r = await self.send(
File "C:\Users\me\AppData\Roaming\Python\Python310\site-packages\pyrogram\methods\advanced\send.py", line 78, in send
r = await self.session.send(
File "C:\Users\me\AppData\Roaming\Python\Python310\site-packages\pyrogram\session\session.py", line 427, in send
return await self._send(data, timeout=timeout)
File "C:\Users\me\AppData\Roaming\Python\Python310\site-packages\pyrogram\session\session.py", line 397, in _send
RPCError.raise_it(result, type(data))
File "C:\Users\me\AppData\Roaming\Python\Python310\site-packages\pyrogram\errors\rpc_error.py", line 70, in raise_it
raise getattr(
pyrogram.errors.exceptions.not_acceptable_406.NotAcceptable: [406 Not Acceptable]: [406 UPDATE_APP_TO_LOGIN] (caused by "auth.SendCode")

UPDATE: I found that Pyrogram needs to be updated as well. So after Pyrogram upgrade from 1.2.09 to 1.2.11.
Thank again for help.

I have pushed v1.24 to PyPi, which fixes login (thus avoiding UPDATE_APP_TO_LOGIN), but I have not had the time to test this version thoroughly, so please make sure to report any issues you find here on GitHub...

client.iter_participants does not return users without a username, can you fix that?

Thank you all. Fixed the problem and now the new sessions work fine.

hi lonami, I want to ask why when I log in my account gets banned, is there a solution?

Yes , i have this problem too

@gsa165lq31a and @Idlessz see #824. This issue is to discuss UPDATE_APP_TO_LOGIN only.

@gsa165lq31a and @Idlessz see #824. This issue is to discuss UPDATE_APP_TO_LOGIN only.

Okay thankyou for the attention

1.24.0

thanks . is ok! 1.24.0

v2 is still in the works, primarily, proxies and entity still needs some work, but it's getting there. People interested in knowing when more updates are made can follow https://t.me/TelethonUpdates.

Any help on this please

Traceback (most recent call last):
File "scraper.py", line 80, in
all_participants = client.get_participants(target_group, aggressive=False)
File "C:\Users\DELL.local\lib\python3.8\site-packages\telethon\sync.py", line 39, in syncified
return loop.run_until_complete(coro)
File "C:\Program Files\Inkscape\lib\python3.8\asyncio\base_events.py", line 616, in run_until_complete
return future.result()
File "C:\Users\DELL.local\lib\python3.8\site-packages\telethon\client\chats.py", line 507, in get_participants
return await self.iter_participants(*args, **kwargs).collect()
File "C:\Users\DELL.local\lib\python3.8\site-packages\telethon\requestiter.py", line 113, in collect
async for message in self:
File "C:\Users\DELL.local\lib\python3.8\site-packages\telethon\requestiter.py", line 74, in anext
if await self._load_next_chunk():
File "C:\Users\DELL.local\lib\python3.8\site-packages\telethon\client\chats.py", line 224, in _load_next_chunk
participants = results[i]
TypeError: 'ChannelParticipants' object is not subscriptable

help me please @Lonami

Input session name: sasaas
Enter phone number or bot token: +998907809436
Is "+998907809436" correct? (y/N): y
The confirmation code has been sent via Telegram app
Enter confirmation code: 20395
Traceback (most recent call last):

File "erfan4lx.py", line 260, in <module>
  loop.run_until_complete(func)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 587, in run_until_complete
  return future.result()
File "erfan4lx.py", line 234, in add_client
  async with Client(session_name, workdir=CLIENTS_DIR) as new_client:
File "C:\Users\E-MaxPCShop\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyrogram\client.py", line 257, in __aenter__
  return await self.start()
File "C:\Users\E-MaxPCShop\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyrogram\methods\utilities\start.py", line 57, in start
  await self.authorize()
File "C:\Users\E-MaxPCShop\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyrogram\client.py", line 327, in authorize
  signed_in = await self.sign_in(self.phone_number, sent_code.phone_code_hash, self.phone_code)
File "C:\Users\E-MaxPCShop\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyrogram\methods\auth\sign_in.py", line 65, in sign_in
  phone_code=phone_code
File "C:\Users\E-MaxPCShop\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyrogram\methods\advanced\send.py", line 81, in send
  else self.sleep_threshold)
File "C:\Users\E-MaxPCShop\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyrogram\session\session.py", line 441, in send
  return await self._send(data, timeout=timeout)
File "C:\Users\E-MaxPCShop\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyrogram\session\session.py", line 411, in _send
  RPCError.raise_it(result, type(data))
File "C:\Users\E-MaxPCShop\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyrogram\errors\rpc_error.py", line 73, in raise_it
  is_unknown=True)
pyrogram.errors.exceptions.not_acceptable_406.NotAcceptable: [406 Not Acceptable]: [406 UPDATE_APP_TO_LOGIN] (caused by "auth.SignIn")

telethon.errors.rpcbaseerrors.AuthKeyError: RPCError 406: UPDATE_APP_TO_LOGIN (caused by SignInRequest)

I am getting this error, anyone know the problem? Ubuntu 20.04 fresh install & can also replicate on macOS

I solved making visible to anyone the telegram profile picture.
See:
https://core.telegram.org/method/contacts.getLocated

Hello dear @ I fixed this to pip install -U Telethon

Hi how are you