Search code examples
telethon

I get an error when I run the code with telethon,api_id


OS : mx-Linux Python : ver(3.9.2) Telethon: ver(1.28.5)

from telethon import TelegramClient
api_id    = 6XXXXXXXXX
api_hash  = 'AYYYYYYYYYYYYYYYYY-ZZZZZZZZZZZZZk'
bot_token = '6XXXXXXXXX:AYYYYYYYYYYYYYYYYY-ZZZZZZZZZZZZZk'

with TelegramClient(bot_token, api_id, api_hash) as client:
    client.loop.run_until_complete(client.send_message('me', 'Hello, myself!'))
<error>
Request caused struct.error: 'i' format requires -2147483648 <= number <= 2147483647: 
InvokeWithLayerRequest(layer=155, query=InitConnectionRequest
(api_id=6XXXXXXXXX,device_model='PC 64bit',system_version='5.10.0',app_version='1.28.5',system_lang_code='en',
 lang_pack='',lang_code='en',query=GetConfigRequest(),proxy=None,params=None))

The api_id I got from @BotFather seems to be a large number, is that a problem?

Got the api_id and api_hash from @BotFather as belows

Done! Congratulations on your new bot. 
You will find it at t.me/MyName_bot. 
You can now add a description, 
about section and profile picture for your bot, 
see /help for a list of commands. By the way, 
when you've finished creating your cool bot, 
ping our Bot Support if you want a better username for it. 
Just make sure the bot is fully operational before you do this.

Use this token to access the HTTP API:
6XXXXXXXXX:AYYYYYYYYYYYYYYYYY-ZZZZZZZZZZZZZk
Keep your token secure and store it safely, 
it can be used by anyone to control your bot.

For a description of the Bot API, 
see this page: https://core.telegram.org/bots/api

Solution

  • That's wrong. @botfather only gives you the token: 6XXXXXXXXX:AYYYYYYYYYYYYYYYYY-ZZZZZZZZZZZZZk.

    6XXXXXXXXX is actually your created bot' user id.

    The api_id and api_hash is personal for the user account, it requires you to create an app at https://my.telegram.org. the two values can then be used in any app and with any bot token you want, repeated and simultaneous usage is allowed.