Closed spencescu closed 4 years ago
The amount of code or traceback you provided is nowhere enough for anyone to efficiently troubleshoot your issue. Please post all relevant code and the full traceback. You should also make sure to check all 3 checkboxes, not just one (after doing what they say).
Traceback (most recent call last):
File "/home/mircea/.local/lib/python3.6/site-packages/NetScraper.py", line 364, in
This time I probably tried to use a code that was for another session
Usually I just don't get any code. Here is my routine:
async def coro_sign_in(self):
try:
await self.client.connect()
if not self.client.is_connected():
await asyncio.sleep(1)
ok = await self.client.is_user_authorized()
if ok:
return True
phone = input("Enter phone:")
await self.client.send_code_request(phone)
login = input('Login code :')
await self.client.sign_in(phone, login)
except: # catch *all* exceptions
self.print_error(sys.exc_info()[0])
return False
# self.client.sign_in(password=pwd)
So the problem is that I never get any code with await self.client.send_code_request(phone)
That only happens when the server is in another country
It's an aws vm
When I run it on Windows+python3.4 or WSL+python3.2 on my own laptop everything works ok
What's the meaning of telethon.errors.rpcerrorlist.AuthKeyUnregisteredError ?
Not yet logged in.
Question - does the code handle these errors from
https://core.telegram.org/method/auth.sendCode
303 | NETWORK_MIGRATE_X | Repeat the query to data-center X |
---|---|---|
303 | PHONE_MIGRATE_X | Repeat the query to data-center X |
My guess is that if we try with country x phone # on a server in country y we may be redirected to a different DC but the client is not able to do that or return a meaningful error and it just hangs...
Is it possible that the problem may be due to incomplete processing of redirections to a different data center like
303 | NETWORK_MIGRATE_X | Repeat the query to data-center X 303 | PHONE_MIGRATE_X | Repeat the query to data-center X
The whole point is to use another DC for authentication It doesn't look like this is done in user.py
It is done. A few lines below you can see a call to switch_dc
. It is also logged so you can see if this is the case.
await self._switch_dc(e.new_dc) does not seem to be defined and is probably not reached
In my understanding: should_raise = isinstance(e, (errors.PhoneMigrateError, errors.NetworkMigrateError))
should_raise appears to be True
if should_raise and await self.is_user_authorized():
raise # raise if is_user_authorized ?
await self._switch_dc(e.new_dc) # is this reached? where is it defined?
does not seem to be defined
"Not seem" is not an option. It is defined in the other classes since this is only partial with some methods. If you don't see the "not defined" error it is obviously defined.
Should raise only raises if the account is logged in, and we're saying it's not logged in yet.
Well, it does not seem to get the authorisation from the new dc.
It should send the code request to the new dc But the code never gets sent
So it looks like the code request does not reach the new dc
In order to reproduce this you need to run hello.py on a server that is on the other side of the world from where the account was registered so you get a different dc to authorise with
That is correct. The hello.py on a US based AWS server works perfect with a US phone # and never gets the login code with a Greek one. However, I can log in to the telegram browser app on the same machine with the Greek number with no issues.
I guess this issue is valid and actionable and needs to be reopened.
Do the logs indicate that phone or network migration is raised? If not how are we supposed to know which is the home DC?
Nothing gets logged. It just hangs.
@Lonami it would be great if you could do the test suggested by @MirceaLutic, if you need any help we can use US test servers and gather whatever you need in terms of logs... It seems a lot of people have this issue, it would be nice to solve it.
I guess the best way to do it is run hello.py on the local IDE with a US phone number
Running locally, when Telethon by default connects to a datacenter different to the one my account is on:
Note in particular:
[ INFO/2020-07-28 19:00:04,817] telethon.client.users: Phone migrated to 4
[ INFO/2020-07-28 19:00:04,817] telethon.client.telegrambaseclient: Reconnecting to new data center 4
So automatic reconnection to a different datacenter as needed is being handled correctly, as I imagined. The code did arrive to Telegram and I could've logged in just fine. The AWS issue seems different. "It gets stuck" is not helpful. I would need to find where and how it gets stuck.
I will reopen the AWS issue because there might be a way to do it, but I doubt I'll look into it. It's simpler to just give it an already-logged-in session, and there are more services out there.
If you both are going to discuss the issue further, please avoid spamming it with so many comments. This is not instant messaging, the replies can be longer and better thought-out.
how can i get this level of logging?
It's also reconnecting properly and sending the request:
[ INFO/2020-07-28 20:30:23,012] telethon.client.users: Phone migrated to 4
[ INFO/2020-07-28 20:30:23,012] telethon.client.telegrambaseclient: Reconnecting to new data center 4
...
[ INFO/2020-07-28 20:30:23,071] telethon.network.mtprotosender: Disconnecting from 149.154.175.59:443/TcpFull...
[DEBUG/2020-07-28 20:30:23,071] telethon.network.mtprotosender: Closing current connection...
[DEBUG/2020-07-28 20:30:23,071] telethon.network.mtprotosender: Cancelling 0 pending message(s)...
[ INFO/2020-07-28 20:30:23,072] telethon.network.mtprotosender: Disconnection from 149.154.175.59:443/TcpFull complete!
[ INFO/2020-07-28 20:30:23,072] telethon.network.mtprotosender: Connecting to 149.154.167.92:443/TcpFull...
[DEBUG/2020-07-28 20:30:23,072] telethon.network.mtprotosender: Connection attempt 1...
[DEBUG/2020-07-28 20:30:23,156] telethon.network.mtprotosender: Connection success!
...
[DEBUG/2020-07-28 20:30:23,939] telethon.extensions.messagepacker: Assigned msg_id = 6854584941351484356 to SendCodeRequest (7f373cd34210)
...
[DEBUG/2020-07-28 20:30:24,059] telethon.network.mtprotosender: Handling RPC result for message 6854584941351484356
Most likely AWS is blocked, as it was said in the other issue a while ago. The library handles reconnections just fine. If you figure out how to make it work in AWS make sure to let everyone know in the other issue.
It works just fine in AWS with a US number, I don't believe anything is blocked.
@Lonami So what you are saying is that AWS is only blocking the connection to the new dc ? This seems highly unlikely to me. I would rather assume that the new dc sees the code request as somehow invalid or incomplete. Do you get any kind of response on sending the code request? Can you spot it in the log?
The snippet I copied from @spencescu shows that it reconnects, re-sends the request and gets a response. If it didn't get a response it would never ask "enter code". The request is executed fine and a response arrives but Telegram does not actually send the code.
Could the response actually contain some error condition? It may be useful to log that response
Also, how do we explain that it is working fine with a local number but not with a foreign one?
It may be useful to log that response
It would leak private information which is why it's not logged. You can use the raw request and print it on your own.
For what is worth, here is a happy path log. Note there is no data center switch...
There is no switch because you logged in just fine:
Signed in successfully as S P
Right - logged in just fine with a US telegram account. The login flow on the same server with the Greek account was posted before and it was directed to another data center, which closed the connection soon after.
I am working on an API application and the code works fine when running on my local machine (in Greece). However, when I install the code on a customer AWS instance (in the US) I never get the login codes. I used my US phone number to sign up for another telegram account and that worked. On the other hand, I am able to log in to telegram web with the Greek number from the US server, so it seems the web app does not have country restrictions, but the API does. Can you please point me to any docs related to this, unless this is a bug?
Checklist
pip install -U https://github.com/LonamiWebs/Telethon/archive/master.zip
and triggered the bug in the latest version.Code that causes the issue
Traceback