Telethon: The phone code entered was invalid... but it should be valid
Hello, I’m trying to implement an automatic account-creation system using smspva API to generate Phone Numbers and get SMS. I’ve coded everything, and smspva seems to work:
I get the phone number and then:
client = TelegramClient(phone_number, api_id, api_hash) //create a session with the phone number as name (in the form +7123456789...)
assert client.connect()
client.send_code_request(phone_number) //phone number (in the form +7123456789...)
Then i place the listener to receive SMS, and I get it:
code = check_sms(number_id)
I’ve printed out the code to see it was correct:
Got Code: 90156
Then i just pass the code into sign_up function with this:
myself = client.sign_up(phone_number, code)
And it fails:
Traceback (most recent call last):
File "account_creator.py", line 35, in <module>
myself = client.sign_up(number[1], code)
File "venv/lib/python3.6/site-packages/telethon/telegram_client.py", line 468, in sign_up
last_name=last_name
File "venv/lib/python3.6/site-packages/telethon/telegram_bare_client.py", line 459, in __call__
result = self._invoke(call_receive, *requests)
File "venv/lib/python3.6/site-packages/telethon/telegram_bare_client.py", line 551, in _invoke
raise next(x.rpc_error for x in requests if x.rpc_error)
telethon.errors.rpc_error_list.PhoneCodeInvalidError: The phone code entered was invalid
It fails also if i replace the sign_up part with this:
myself = client.sign_up(phone_number, input('Enter code:'))
If I type the code manually it still fails, but the code should be correct… as you can see:
{"response":"1","number":"123456789","id":2222260,"text":"16782","extra":"0","karma":33.975,"pass":"","sms":"16782","balanceOnPhone":0}
Got Code: 16782
Enter the Code: 16782
Traceback (most recent call last):
File "account_creator.py", line 35, in <module>
myself = client.sign_up(number[1], input('Enter the Code: '))
File "venv/lib/python3.6/site-packages/telethon/telegram_client.py", line 468, in sign_up
last_name=last_name
File "venv/lib/python3.6/site-packages/telethon/telegram_bare_client.py", line 459, in __call__
result = self._invoke(call_receive, *requests)
File "venv/lib/python3.6/site-packages/telethon/telegram_bare_client.py", line 551, in _invoke
raise next(x.rpc_error for x in requests if x.rpc_error)
telethon.errors.rpc_error_list.PhoneCodeInvalidError: The phone code entered was invalid
I have no idea what else I could try. I’m pretty new to Python. Also I’m just using all my smspva balance for testing ahahah
Thanks a lot 😃
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 25 (9 by maintainers)
@Lonami Oh well… just tried with my phone.
I kept sign_up and got the “code invalid”. Tried with sign_in and worked (of course i already had a telegram account). Maybe I have to try with sign_in first and then if it fails sign_up?
If you send the code over Telegram itself, it will expire inmediatly. If you’re going to send it over Telegram, obfuscate it somehow first.