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

The api_id/api_hash combination is invalid #836

Closed
tomillo opened this issue Jun 5, 2018 · 18 comments
Closed

The api_id/api_hash combination is invalid #836

tomillo opened this issue Jun 5, 2018 · 18 comments

Comments

@tomillo
Copy link

tomillo commented Jun 5, 2018

It turns out that my script worked perfectly until I tried using it on another server, and from that moment on it stopped working and the error appears api_id / api_hash combination is invalid. I have checked api_id and hash_id many times, but they haven't changed.. so I would appreciate some help. Thanks.

Traceback (most recent call last):
  File "mytelegram.py", line 41, in <module>
    tclient.send_code_request(phone)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/telethon/telegram_client.py", line 241, in send_code_request
    result = self(SendCodeRequest(phone, self.api_id, self.api_hash))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/telethon/telegram_bare_client.py", line 486, in __call__
    result = self._invoke(call_receive, request, ordered=ordered)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/telethon/telegram_bare_client.py", line 583, in _invoke
    raise next(x.rpc_error for x in requests if x.rpc_error)
telethon.errors.rpc_error_list.ApiIdInvalidError: The api_id/api_hash combination is invalid
@Lonami
Copy link
Member

Lonami commented Jun 5, 2018

See #46, we already had issues with this. Specifically this comment:

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.

Does your api_id have over 6 digits? Maybe, we had issues when they started having 6 digits, perhaps we have them again with them being 7. It wouldn't surprise me. My api_id/api_hash (with 5 digits) works just fine.

Edit: Oh, my bad, you already commented there. Oh, well.

@tomillo
Copy link
Author

tomillo commented Jun 5, 2018

Thanks @Lonami for your reply. My api_idhave 6 digits.

@tomillo
Copy link
Author

tomillo commented Jun 8, 2018

Still with the same error. Any help?

@Lonami
Copy link
Member

Lonami commented Jun 8, 2018

No, sorry, no idea. Only thing I can think of is use another API ID/hash.

@tomillo
Copy link
Author

tomillo commented Jun 8, 2018

There’s a way to renew API ID/hash with the same account?

@Lonami
Copy link
Member

Lonami commented Jun 8, 2018

No.

@tomillo tomillo closed this as completed Jun 13, 2018
@zsamora
Copy link

zsamora commented May 18, 2020

check for spaces, mine was not working because of a blank space in the beginning

@alvaropc
Copy link

Same problem here.
Telegram keeps giving IDs with more than 5 digits, why this cannot be solved?

@Lonami
Copy link
Member

Lonami commented Aug 13, 2020

Telegram keeps giving IDs with more than 5 digits, why this cannot be solved?

Because there are more than 99_999 developers, there can't be new IDs with less digits. If you're talking about the bug itself, there is not much the library can do. If Telegram rejects an API ID, the best you can do is either wait, email support, or try to get a new API ID in another account.

@kylethedeveloper
Copy link

This is so ridiculous.

@Lonami
Copy link
Member

Lonami commented Mar 6, 2021

Yes, but there's nothing Telethon can do about it. Waiting for a while after creating the app may make the problem get solved on its own. Not sure, I only have one phone number to make apps with, and I did this a really long time ago.

@kylethedeveloper
Copy link

I actually figured it out. It was my fault I guess.

I created a bot account from BotFather and I was using my bot's API token for all the variables; api_id, api_hash and bot_token.
I did not realize that I had to use my api_id and api_hash for those variables. So to summarize:

api_id = <youraccount_api_id>
api_hash = <youraccount_api_hash>
bot_token = '123456789:apitoken_ofyourbot_thatyougetfrom_botfather'

I was actually going back and forth through the documentation and realized that I was wrong after reading TelegramClient page. In my opinion it should be mentioned on here too.

BTW both my own api_id and bot's api_id are longer than 5 chars.

@Lonami
Copy link
Member

Lonami commented Mar 6, 2021

The "here" you mention already says:

(at the top) Note: This API ID and hash is the one used by your application, not your phone number. You can use this API ID and hash with any phone number or even for bot accounts.

Signing In as a Bot Account […] You will still need an API ID and hash.

API ID, API hash, and bot token, all are different terms. But if you can improve the documentation, feel free to send a PR.

@Dhinendran
Copy link

@kylethedeveloper I have all the scenarios both key and mobile number throwing

telethon.errors.rpcerrorlist.ApiIdInvalidError: The api_id/api_hash combination is invalid (caused by SendCodeRequest)

any on help me out. my api_id is 7 digit

@unknownseason
Copy link

@kylethedeveloper I have all the scenarios both key and mobile number throwing

telethon.errors.rpcerrorlist.ApiIdInvalidError: The api_id/api_hash combination is invalid (caused by SendCodeRequest)

any on help me out. my api_id is 7 digit

same problem

@slkass
Copy link

slkass commented Jul 16, 2021

@kylethedeveloper I have all the scenarios both key and mobile number throwing

telethon.errors.rpcerrorlist.ApiIdInvalidError: The api_id/api_hash combination is invalid (caused by SendCodeRequest)

any on help me out. my api_id is 7 digit

same

@sdfg2
Copy link

sdfg2 commented Jul 16, 2021

I have the same problem with a 7 digit id. Is it a case of waiting like it was with #46 ?

@sgerodes
Copy link

I have a 9 digit long API_ID and it is also not working.

armanexplorer added a commit to armanexplorer/Telethon that referenced this issue Aug 28, 2022
As mentioned in LonamiWebs#836 by kylethedeveloper, it will be clearer if we more explicitly mention the origin of the API ID and hash used in bot accounts signing in. 
Also, the example misleads that maybe bot_token results from api_id and hash_id concatenation.

- Add some minor descriptions to the bot accounts section
- Clarify and then unify the examples
armanexplorer added a commit to armanexplorer/Telethon that referenced this issue Aug 28, 2022
As mentioned in LonamiWebs#836 by kylethedeveloper, it will be clearer if we more explicitly mention the origin of the API ID and hash used in bot accounts signing in. 
Also, the example misleads that maybe bot_token results from api_id and hash_id concatenation.

- Add some minor descriptions to the bot accounts section
- Clarify and then unify the examples
armanexplorer added a commit to armanexplorer/Telethon that referenced this issue Aug 28, 2022
As mentioned in LonamiWebs#836 by kylethedeveloper, it will be clearer if we more explicitly mention the origin of the API ID and hash used in bot accounts signing in. 
Also, the example misleads that maybe bot_token results from api_id and hash_id concatenation.

- Add some minor descriptions to the bot accounts section
- Clarify and then unify the examples
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

10 participants