LonamiWebs / Telethon

Pure Python 3 MTProto API Telegram client library, for bots too!
https://docs.telethon.dev
MIT License
9.72k stars 1.39k forks source link

The phone number a user is trying to use for authorization is associated with DC 5 (caused by SendCodeRequest) #3777

Closed mx-key closed 2 years ago

mx-key commented 2 years ago

I am trying to register telegram accounts using phone numbers from different countries. For most phones, a PhoneMigrateError is thrown when a SendCodeRequest is requested. In my opinion, this occurs when the client's phone number and the phone number to which the code is sent are in different data centers.

Code that causes the issue

result = await client(functions.auth.SendCodeRequest(
    phone_number, acc["api_id"], acc["api_hash"],
    settings=types.CodeSettings( allow_flashcall=False, current_number=True, allow_app_hash=False )
))
Lonami commented 2 years ago

There is no bug. The error comes from Telegram and it works as intended.

mx-key commented 2 years ago

If so, why does a client that is authorized from a phone from Ukraine throw a PhoneMigrateError exception when trying to register from any phone in some countries. Only numbers that are located in the same data center where the account is registered from which registration is made are available for registration.

mx-key commented 2 years ago

If api_id, api_hash are linked to a Ukrainian phone number, I can't register accounts using phones in 80% of countries. What to do in this case?

Lonami commented 2 years ago

API ID and hash are not linked to specific data centers as far as I know. Raw API does not automatically handle DC migrations, but client.sign_up should. This is offtopic here.

mx-key commented 2 years ago

problem with SendCodeRequest - does it automatically handle DC migrations? API ID and hash are not linked - Then why DC is listed at https://my.telegram.org/apps and I can't change it? image

Lonami commented 2 years ago

That's the test server. The library has a hardcoded datacenter but switches to others at runtime if necessary. Friendly methods do this. Raw API does not.