Closed xxxsen closed 3 years ago
Hey @xxxsen, thanks for question!
This is trouble of telegram api, all clients needs to automatically switch DCs between available. Also, this error is really specific, we don't know how to process it (code of dc is invluded in error id). Btw, we know about this problem since #12 was created. If you have any idea how to process this error code, let me know please.
https://itnext.io/source-code-walkthrough-of-telegram-ios-part-4-mtproto-connections-22ef2e5b339
"Enter Phone Number" part of this article shows how to switch datacenter, wish it would help you to solve this issue.
On Mon, Oct 12, 2020, 04:13 Richard Cooper notifications@github.com wrote:
Hey @xxxsen https://github.com/xxxsen, thanks for question!
This is trouble of telegram api, all clients needs to automatically switch DCs between available. Also, this error is really specific, we don't know how to process it (code of dc is invluded in error id). Btw, we know about this problem since #12 https://github.com/xelaj/mtproto/issues/12 was created. If you have any idea how to process this error code, let me know please.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/xelaj/mtproto/issues/22#issuecomment-706761541, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5TKVFFJTLLZNEXRSSSLRLSKIGVRANCNFSM4SLZBXWQ .
@xxxsen thanks a lot! I'll research this issue, and answer here until closing it. This article will help
@ololosha228 Also, I have this problem. you can fix it? or what can I do for fixing?
@airani i have some work in this case, i'll commit part of my solution to this issue in experimental branch and let you know)
In general, there is not so much stuff to do for dealing this error code, you need to say telegram.Client
change few session settings: set special ip address and server salt, so i hope, we can fix it in a few days!
@ololosha228 you saw this page? https://core.telegram.org/api/datacenter
@airani this branch is leads to fix this issue
@ololosha228 you saw this page?
Yeah, but i still don't understand their point of logic to do stuff like this (cause servers may proxying requests to another, but they are not). Anyway, i working on in, you can help too)
I found solution to fix this bug, when you have got this error for a phone number you should change serverHost
or DC id to X number in PHONE_MIGRATE_X
and again call NewClient
with new ClientConfig
and note that delete the session file. and try again in a loop until you select the right DC for that phone number.
List of Telegram DC:
ID | IP | PORT |
---|---|---|
1 | 149.154.175.58 | 443 |
1 | 149.154.175.55 | 443 |
2 | 149.154.167.50 | 443 |
2 | 149.154.167.51 | 443 |
2 | 149.154.167.151 | 443 |
3 | 149.154.175.100 | 443 |
4 | 149.154.167.91 | 443 |
4 | 149.154.165.111 | 443 |
5 | 91.108.56.151 | 443 |
this is major bug, break the whole library
@codenoid it's not a bug, it's a feature)))
Okay, without any jokes, we agree that library must change DC automatically (as many other stuff), i'll prioritize this feature to top level.
Unfortunately, i don't have much time to fix it, maybe someone could collect data about which usual telegram client do automatically without user requests (must dig in tdlib or android clients, they must have automatic jobs like change dc, recreate or repair sessions etc), and i'll just implement it. But i need info about this firstly.
i don't know, but i still able to send code with https://github.com/sdidyk/mtproto
note: but after I input the confirmation code (with sdidyk/mtproto
), my telegram account goes banned, i don't know, maybe it's uses old API
@codenoid i'm sorry to hear that :cry:
sdidyk/mtproto has bad credentials of app (app id 41994 is banned due to multiple cases spamming and doing malware stuff). Also, few parts of this (xelaj/mtproto) package was reimplemented, but i can say that sdidyk/mtproto doesnt have proper logic of automated things.
wait what? i didn't close it, its only WIP!
@xxxsen @airani @codenoid and also @patrikhermansson, i have some news!
So i had a few time to fix it, but it's looks so messy as i think. This commit will help. I hope.
@codenoid @xxxsen due to this error affects to specific phone numbers, can you please test this fix, and give us report?
Can confirm that it works well in my testing! Thanks for fixing and sorry for late reply.
@patrikhermansson check out also this branch
We had reworked literally all package include new tl parser, which doesn't panic every second, also we reimplemented codegen tool, now personally me don't cry when i'm scrolling telegram package in godoc))))
Hi! Sorry about this but clearly didn't test enough earlier. It doesn't work yet I'm afraid. Have not solved it but a few issues I found:
1) tryToProcessErr() in mtproto.go doesn't match with the PHONE_MIGRATE error. The switch statement matches against "PHONE_MIGRATE_X" but the e.Message is "PHONE_MIGRATE_4" (and assumign _1, _2, _3 etc.). This is an easy fix with somethign like if strings.Contains(e.Message, "PHONE_MIGRATE_") {}
instead.
2) e.AdditionalInfo
does not contain DC id, it's nil which means newIP, found := m.dclist[e.AdditionalInfo.(int)]
panics. Might be that we have to parse the e.Message and get the DC id from there instead.
3) However, even changing these things, it doesn't work. I get the following error:
[]uint8{ 0x00, 0x00, 0x00, 0x00, } &errors.errorString{ s: "context canceled", }
Apologies again for being mistaken in the previous message.
@patrikhermansson errors with additional data (like EMAIL_UNCONFIRMED_X
PASSWORD_TOO_FRESH_X
etc.) extracting data from simple text and giving you extended struct with custom data and native error name (you can research TryExpandError implementation)
But i'm worried, that you didn't solve this issue, could you please post here github gist with testing code? Maybe we need to add more docs of how to solve errors with additional data...
Ok had a look. Yeah you're right, there's an issue in TryExpandError on line 77. It should be if choosedPrefixSuffix == nil
not if choosedPrefixSuffix != nil
.
But even if I fix this (which sorts point 1 and 2 in my previous comment). I still get the error:
[]uint8{ 0x00, 0x00, 0x00, 0x00, } &errors.errorString{ s: "context canceled", }
So this is separate. Gonna see if i can sort example code
TryExpandError error is fixed in new_decoder_refactoring branch so not gonna do a pull request but will try to figure out the context issue. Clearly one that gets cancelled somewhere
Due to multiple responses, this bug was fixed in release candidate branch, so i'll close it
о боже ничего не работает об оже
эээ чо PHONE_MIGRATE_2
эээ чо PHONE_MIGRATE_2
а ничо нормально общайся
getting this error, can please someone help
Error calling Telegram API: auth.sendCode { : 'mtrpc_error', error_code: 303, error_message: 'PHONE_MIGRATE_5' }
const createMTProtoInstance = (dcId = null, serverHost = null) => {
return new MTProto({
api_id: parseInt(process.env.TELEGRAM_API_ID),
api_hash: process.env.TELEGRAM_API_HASH,
...(dcId ? { dcId } : {}),
...(serverHost ? { server_address: serverHost } : {}),
storageOptions: {
path: path.resolve(
__dirname,
dcId ? `./data/dc${dcId}.json` : "./data/default.json"
),
},
});
};
let mtproto = createMTProtoInstance();
app.post("/auth/start", async (req, res) => {
const { phone } = req.body;
console.log("PHONE", phone);
if (!phone) {
return res.status(400).json({ error: "Phone number is required" });
}
// Ensure international format
const formattedPhone = phone.startsWith("+") ? phone : `+${phone}`;
enhancedLog("Auth Start", `Attempting to send code to: ${formattedPhone}`);
try {
mtproto = createMTProtoInstance();
const { phone_code_hash } = await handleDCMigration(
mtproto,
"auth.sendCode",
{
phone_number: formattedPhone,
settings: {
_: "codeSettings",
},
}
);
enhancedLog("Auth Start", "Code sent successfully", { phone_code_hash });
res.status(200).json({
phone_code_hash,
message: "Code sent to Telegram!",
phone: formattedPhone,
});
} catch (error) {
logError("Auth Start", error);
res.status(500).json({
error: "Failed to send code",
details: error.message,
fullError: error,
});
}
});
Hey @Salman-2523, you should connect to DC 5 if you getting this error. Information about data centers and ip addresses you can fetch by calling auth.getConfig request (or similar name, i honestly don't remember exact method name), so just reconnect to that dc — and there you go, easy peasy 😉
run auth example and get error msg like this.