The phone code entered was invalid... but it should be valid

See original GitHub issue

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 😃

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:25 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
mircoianesecommented, Apr 14, 2018

@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?

0reactions
VarunChilukuricommented, Apr 5, 2021

Hi @Lonami,

I hope you don’t think this is too much of a bother, but I was wondering if you could clarify how I would obfuscate the code, as I’m still unable to understand what you mean by reading this thread. Here’s a rough idea of what I’m trying to achieve: User enters phone -> I store their email -> they input the code they received -> I use the code to log in. I’m trying to do this without having to enter anything into the terminal, since I want it to be all automatic and require no intervention from me.

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does it keep saying my phone number is invalid ... - Quora
It means that phone number has not been assigned to a landline or to a mobile phone. It is in the queue to...
Read more >
Why am I seeing an error with a valid phone number when ...
When attempting to register for an account using a valid phone number, I'm getting errors: Please do not enter country code in your...
Read more >
How to fix this error “must be a valid phone number. Double ...
If you found this type of error “must be a valid phone number. Double check that it has a full international country code...
Read more >
How to Fix “Please enter a valid phone number” on Twitter
The error happens when you enter an invalid number on Twitter. An invalid number means that Twitter will not be able to send...
Read more >
Why do I get an error that says “invalid phone number” when ...
The application displays an error that says "invalid phone number". What should I do? You will receive an error stating "Invalid phone number" ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found