Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPCError(...), 'The api_id/api_hash combination is invalid.' #46

Closed
chabanovsky opened this issue Apr 7, 2017 · 47 comments
Closed

RPCError(...), 'The api_id/api_hash combination is invalid.' #46

chabanovsky opened this issue Apr 7, 2017 · 47 comments

Comments

@chabanovsky
Copy link

chabanovsky commented Apr 7, 2017

When I run python3 try_telethon.py it all the time says

RPCError(...), 'The api_id/api_hash combination is invalid.'

OS: MacOS, Ubuntu 12.04.

It even does not want to connect. The error occurs on the first self.connect call (Could not stabilise initial connection). What is worth, occasionally this call works. But all the time it fails on sending a code (SendCodeRequest). I use 2 different telegram accounts. The result is the same.

I do as it's written in the readme:

  • Run the tl_generator.py
  • Create and edit the settings
  • python3 try_telethon.py

I get the same result in case of using an installed through the pip version.

Could you please tell, if I should do something else.

Update

When the connect call works, it returns the following

(config (ID: 0x3af6fb5f) = (phonecalls_enabled=None, date=2017-04-07 11:43:30, expires=1491558606, test_mode=False, this_dc=5, dc_options=['(dcOption (ID: 0x5d8c6cc) = (ipv6=None, media_only=None, tcpo_only=None, id=1, ip_address=149.154.175.50, port=443))', '(dcOption (ID: 0x5d8c6cc) = (ipv6=True, media_only=None, tcpo_only=None, id=1, ip_address=2001:0b28:f23d:f001:0000:0000:0000:000a, port=443))', '(dcOption (ID: 0x5d8c6cc) = (ipv6=None, media_only=None, tcpo_only=None, id=2, ip_address=149.154.167.51, port=443))', '(dcOption (ID: 0x5d8c6cc) = (ipv6=True, media_only=None, tcpo_only=None, id=2, ip_address=2001:067c:04e8:f002:0000:0000:0000:000a, port=443))', '(dcOption (ID: 0x5d8c6cc) = (ipv6=None, media_only=None, tcpo_only=None, id=3, ip_address=149.154.175.100, port=443))', '(dcOption (ID: 0x5d8c6cc) = (ipv6=True, media_only=None, tcpo_only=None, id=3, ip_address=2001:0b28:f23d:f003:0000:0000:0000:000a, port=443))', '(dcOption (ID: 0x5d8c6cc) = (ipv6=None, media_only=None, tcpo_only=None, id=4, ip_address=149.154.167.91, port=443))', '(dcOption (ID: 0x5d8c6cc) = (ipv6=True, media_only=None, tcpo_only=None, id=4, ip_address=2001:067c:04e8:f004:0000:0000:0000:000a, port=443))', '(dcOption (ID: 0x5d8c6cc) = (ipv6=None, media_only=True, tcpo_only=None, id=4, ip_address=149.154.165.120, port=443))', '(dcOption (ID: 0x5d8c6cc) = (ipv6=None, media_only=None, tcpo_only=None, id=5, ip_address=91.108.56.165, port=443))', '(dcOption (ID: 0x5d8c6cc) = (ipv6=True, media_only=None, tcpo_only=None, id=5, ip_address=2001:0b28:f23f:f005:0000:0000:0000:000a, port=443))'], chat_size_max=200, megagroup_size_max=5000, forwarded_count_max=100, online_update_period_ms=120000, offline_blur_timeout_ms=5000, offline_idle_timeout_ms=30000, online_cloud_timeout_ms=300000, notify_cloud_delay_ms=30000, notify_default_delay_ms=1500, chat_big_size=10, push_chat_period_ms=60000, push_chat_limit=2, saved_gifs_limit=200, edit_time_limit=172800, rating_e_decay=2419200, stickers_recent_limit=30, tmp_sessions=None, pinned_dialogs_count_max=5, call_receive_timeout_ms=20000, call_ring_timeout_ms=90000, call_connect_timeout_ms=30000, call_packet_timeout_ms=10000, disabled_features=None))

@Lonami
Copy link
Member

Lonami commented Apr 7, 2017

Create and edit the settings

Have you made sure that you're using the right combination of API ID and API hash? You get these from https://my.telegram.org.

@chabanovsky
Copy link
Author

chabanovsky commented Apr 7, 2017

@Lonami Thank you for the reply!
I did! I did it twice from two different accounts. More over on the Internet I found somebody's api_id/api_hash and it works. So, it looks like a bug on the Telegram side. I wrote to the their support team. Lets see what they answer. Could you please do not delete this issue because I mentioned it on the report. As soon as they contact me back I'll put the reply here and close the issue if it's a server bug.

@Lonami
Copy link
Member

Lonami commented Apr 7, 2017

Okay, we can keep this open. Good luck and keep me updated :)

@Vel-Rus
Copy link

Vel-Rus commented Apr 9, 2017

I have the same problem: (RPCError(...), 'The api_id/api_hash combination is invalid.').
I tried on two accounts.

@Lonami
Copy link
Member

Lonami commented Apr 10, 2017

That's really strange, I have never had this problem. Not sure what it could actually be. I assume https://my.telegram.org provides no insight on the problem either?

I use 2 different telegram accounts.
I tried on two accounts.

By this do you mean you're also using 2 different combinations of api_id and api_hash, right? It's strange it doesn't happen always, because if it did, perhaps the Spam FAQ could apply or some other reason.

Could you try with the "public" API ID/hash from these lines? But please don't abuse it! API ID and hash should be kept private, but since that's public, I guess it's okay to just try.

@Vel-Rus
Copy link

Vel-Rus commented Apr 10, 2017

Yes, I used 2 different combinations of api_id and api_hash. (Used 2 phone numbers)
I tried the "public" API ID/hash, it worked, I corresponded with chat id = 1, Telegram.
But with my API ID/hash does not work.)))

@Lonami
Copy link
Member

Lonami commented Apr 10, 2017

I corresponded with chat id = 1, Telegram

What did you mean?

@Vel-Rus
Copy link

Vel-Rus commented Apr 10, 2017

After authorization, a hint appeared: "Enter the chat id or command", I entered 1. This is id of The Telegram. And I could send it messages and receive.

@userusr
Copy link

userusr commented Apr 11, 2017

I have the same problem (RPCError(...), 'The api_id/api_hash combination is invalid.'). I got my api_id/hash about three days ago. I also tried the "public" API ID/hash, after phone verification the error occurred (RPCError(...), 'The phone number is not yet being used.').

@Lonami
Copy link
Member

Lonami commented Apr 11, 2017

Welp… More people having this issue than I would have thought. I literally extracted that error from the Telegram documentation, quote:

400 BAD_REQUEST

The query contains errors. In the event that a request was created using a form and contains user generated data, the user should be notified that the data must be corrected before the query is repeate

Examples of Errors:

  • API_ID_INVALID: The api_id/api_hash combination is invalid

After looking for this error on more places I found this issue on ex3ndr's API, the last comment suggesting to try a different IP address manually:

static const BuiltInDc _builtInDcs[] = {
	{ 1, "149.154.175.50", 443 },
	{ 2, "149.154.167.51", 443 },
	{ 3, "149.154.175.100", 443 },
	{ 4, "149.154.167.91", 443 },
	{ 5, "149.154.171.5", 443 }
};

It's strange, though, because the error is API_ID_INVALID, not *_MIGRATE_X (which are, in theory, handled correctly).

Some people using TLSharp had the same issue, even on more recent ones, though they got no reply with a fix for it. Not even Stack Overflow seems to have an answer…

Edit: After trying their suggestion I successfully managed to use my production IP, which is said to be "DC 2": 149.154.167.50. You can perform this change here, though you must be logged out (no *.session file), or the previous IP will be loaded and used.

Edit 2: It would be good if you could test other libraries out there with the offending API ID and hash to confirm whether it's Telethon related.

@HemmatSharp
Copy link

I have same error API_ID_INVALID in 2 different account new created using tlsharp, but in my old account tlsharp works perfect, I changed server address to test and production IP or { 1, "149.154.175.50", 443 }, { 2, "149.154.167.51", 443 },{ 3, "149.154.175.100", 443 },{ 4, "149.154.167.91", 443 }, { 5, "149.154.171.5", 443 } but not result. please help me to resolve this problem. thanks 4 your attention.

@Lonami
Copy link
Member

Lonami commented Apr 11, 2017

but in my old account tlsharp works perfect

Does Telethon work with the one working on TLSharp?

@HemmatSharp
Copy link

sorry I use tlsharp in C#, I've never worked with telethon.

@Lonami
Copy link
Member

Lonami commented Apr 11, 2017

I've never worked with telethon

You cannot pretend me to help you with TLSharp, that is not my library. You should not ask here for help if you're not using this library (not to mention, we're debating a specific issue, not solving questions even if they're related). So, if you're here, it would be nice if you were willing to help to keep this on topic. I need the help of people using both Telethon and other libraries to confirm whether it's Telethon related or a Telegram issue.

@HemmatSharp
Copy link

OK, Thank you, but error message is same and solution to one library can help to other. anyway Thank you for your attention.

@HemmatSharp
Copy link

HemmatSharp commented Apr 11, 2017

whether it's Telethon related or a Telegram issue

most probably it's telegram issue, but Currently there are no resources.

@AlexMuller666
Copy link

The same problem, checked two accounts.

@Vel-Rus
Copy link

Vel-Rus commented Apr 12, 2017

Also does not work with "DC 2" IP

@Lonami Lonami added the help wanted Details, logs, code is wanted label Apr 12, 2017
@StrangePers
Copy link

As far as i know this problem has something to do with the length of new API keys. All API keys that are 5 digits or less - works perfectly. But new ones has 6 digits. And they fail to authorize.

@Lonami
Copy link
Member

Lonami commented Apr 12, 2017

But new ones has 6 digits. And they fail to authorize.

As far as I know, keys are sent as integer values, not as strings. So this should be no issue I guess. But who knows what they can be doing server side… (I mean, it makes more sense to fail the check for a string length, but numbers don't have a "length" per se unless doing log10())

@StrangePers
Copy link

StrangePers commented Apr 12, 2017

As far as I know, keys are sent as integer values, not as strings.

I know.. And i was very surprised too. But i checked myself 4 combinations of api/key old ones and new ones with teleton, MadelineProto, golang mtproto and all 5 digits worked, but no 6 digits ever succeded.

P.S. Here is TLSharp same issue with traces. No solution so far...
sochix/TLSharp#442

@Lonami
Copy link
Member

Lonami commented Apr 12, 2017

with teleton, MadelineProto, golang mtproto and all 5 digits worked, but no 6 digits ever succeded.

Hey! Thank you very much for doing that. We can confirm the issue is not Telethon related per se. Nevertheless I will keep this open so people can see this discussion and participate.

@Kylmakalle
Copy link
Contributor

Kylmakalle commented Apr 13, 2017

@Lonami

I successfully managed to use my production IP, which is said to be "DC 2": 149.154.167.50

Finally, it works for me!
Maybe other should try more IP's?

UPDATE
After some manipulations (I think, I deleted my *. Session file and there are all the problems starts)
30 restarts and changing ips results nothing, very disappointed now.

UPDATE 2

Finally, it works for me![2]
Some weird things are working for me.

  1. Changing DC IP to one that i got from https://my.telegram.org/apps (Production configuration)
    Optionaly, maybe it does not affect anything: destroyed all my CLI telegram logins, terminated all CLI related instances on my Ubuntu machine
  2. Successfully logging into InteractiveTelegramClient using "public" API ID/hash, here i verified my telegram code through the app.
  3. Then, changing API ID/hash to lines that i got at https://my.telegram.org/apps
  4. Successfully logging into InteractiveTelegramClient using MY API ID/hash, but now, without verifying my telegram code (So, *.session file do some magic stuff there with api/hash and DC IP, i think, maybe *.Session should be verified using public API ID/hash or using some special DC IPs.)

@AlexMuller666
Copy link

Telegram informed me that they have fixed this problem. Use twitter to communicate with them

@Kylmakalle
Copy link
Contributor

Kylmakalle commented Apr 13, 2017

@AlexMuller666

Telegram informed me that they have fixed this problem.

Can't find any proof twits, another guy is still experiencing this problem.

@AlexMuller666
Copy link

Hmmm. I checked now. I can log in

@Vel-Rus
Copy link

Vel-Rus commented Apr 13, 2017

Hooray. I also checked, login works!!!)))

@HemmatSharp
Copy link

that's oooooooooook
it works now

@Lonami
Copy link
Member

Lonami commented Apr 13, 2017

Nice to know it works now! I'm closing this issue then.

@Lonami Lonami closed this as completed Apr 13, 2017
@Lonami Lonami removed the help wanted Details, logs, code is wanted label Jun 16, 2017
@tomillo
Copy link

tomillo commented Jun 4, 2018

I have the same issue. So what's the definitive solution? Can anyone help me?

@Freddorick
Copy link

Just FYI: I'm having the same issue with a six digit id. Four digits work fine. The issue also occurs in other Telegram libraries and is unrelated to Telethon. I guess that this will be fixed by telegram in the near future, so I did not invest a lot of time into finding a workaround.

@johngh
Copy link

johngh commented Dec 21, 2018

I was having the same problem and found a solution to this while I was reading this page, so in case it helps someone...
I was reading my API and hash from a config file using configparser, and had this:

[API]
ID: 123456
Hash: '1234567890abcdef1234567890abcdef'

(*#valuesChangedToProtectTheInnocent)

Lonamie's comment #issuecomment-293615300 gave me a clue to try removing the single quotes.

When I removed the single quotes from the Hash line, it suddenly started working \o/
Thank you

@mabdelaziz77
Copy link

Thanks @johngh
Your solution saved my time.
I have had the same issue, and removing the single quotes from the api_hash solved it!

@kingraphaii
Copy link

@johngh Tried that, still no dice

@sgerodes
Copy link

sgerodes commented Dec 21, 2021

I am experiencing the same issue still. My id is 9 digit long

@AntonSmirnov2
Copy link

AntonSmirnov2 commented Jul 4, 2022

Hi! I receive same problem!

I was tried to create session with telethon.sync and failed, but async version can do it!

Hope it will help to someone

@akshitadixit
Copy link

@AntonSmirnov2 could you please share the snippet of your code that fixed the issue?

@Lonami
Copy link
Member

Lonami commented Jul 13, 2022

The code should not matter (unless you actually wrote the hash value wrong, or have spaces or quotes in it, neither of which should be there). The more likely answer is that the API ID and hash take a while to "activate" and be valid and all you have to do is wait (not sure how long).

@alexferreras
Copy link

@Lonami I'm facing the same initial issue, is there a way to accelerate the activation id/hash from telegram?

@Lonami
Copy link
Member

Lonami commented Oct 11, 2022

I have never experienced this issue myself. I have no idea why Telegram behaves this way, or how the issue can be resolved. I cannot offer much help. From what I've seen the problem solves itself after some time. I don't know anything else. This is beyond Telethon's control.

@Svarog89
Copy link

I have the same issue. So what's the definitive solution? Can anyone help me?

@vpinigin
Copy link

started to encounter the same problem, need help
previous answers seem not to work for me

@alirezaPahlavanzadeh
Copy link

I have the same problem too.I tried with two numbers but the problem is still there

@Maizerer
Copy link

@alexferreras Just like you 3 days ago I ran into this problem when I created an application on https://my.telegram.org / And as @Lonami said, you just have to wait. It's been 3 days and today I lost an error and everything worked

@Svarog89 @vpinigin @alirezaPahlavanzadeh If you have created the app recently, just wait a few days

@dunghm19
Copy link

dunghm19 commented Apr 4, 2023

check format phone number

@sergioea
Copy link

sergioea commented Sep 12, 2023

First of all, English is not my language, so sorry if I make mistakes.
I have had this problem for months. Suddenly I get this error and after 2 or 3 days it disappears.
However, this last time it had not worked for a week.
I've been trying some things and finally one has worked.
What I have done has been the following:

  1. Delete the .session file.
  2. Write a very simple script in order to create a new .session file with a different name than the original. In my case I have used this simple code which is used to obtain the list of users of a channel (that doesn't matter, I just want it to create a new .session):
import telethon

api_id = ****
api_hash = '****'
channelT = ****

client = telethon.TelegramClient('newFile', api_id, api_hash)

async def main():

    users = await client.get_participants(channelT)

with client:
    client.loop.run_until_complete(main())
  1. I run the script, it asks me for the phone number (with international code +) and the confirmation code, and it creates a new .session without giving the error.
  2. I rename the .session to old name and I can now use my old code without the error.

I hope this helps someone.

@cybertuck
Copy link

I had such issue with telethon connected via Web (QR code). I cleaned .session and .db files. Executed simple script similar to sergioea, then confirmed with a code sent to TG. After that error is gone for my main scirpt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests