DEV Community

Discussion on: Checking if a phone number is on Telegram, using TDLib and Python

Collapse
 
hafizusman924 profile image
Usman Ali

TypeError Traceback (most recent call last)
in ()
12 response.wait()
13 counter += 1
---> 14 user_ids = response.update['user_ids']
15 if user_ids[0] == 0:
16 print('This contact is NOT using Telegram.'+value)

TypeError: 'NoneType' object is not subscriptable

After Running this code i check only 1000 number and after this this code stop working. Because number error. when i change phone number this code again start working perfectly. Can you please guide me who i can avoid this error?

!python3 -m pip install python-telegram
from google.colab import drive
drive.mount('/content/drive')

import pandas as pd
from telegram.client import Telegram

tg = Telegram(
api_id='Write Your Api',
api_hash='Write Your Hash',
phone='Write you Number',
database_encryption_key='hisunny1',
)

tg.login()
from time import sleep

counter = 0
tel_num = []
for x, value in df.Number.iteritems():

response = tg.call_method('importContacts', {
'contacts': [
{'phone_number': '+'+value},
]
})
response.wait()
counter += 1
user_ids = response.update['user_ids']
if user_ids[0] == 0:
print('This contact is NOT using Telegram.'+value)
sleep(15)
else:
print(f'¡This contact({user_ids[0]}) uses Telegram!'+value)
tel_num.append('+'+value)
sleep(15)

Collapse
 
luvejo profile image
Luis Velásquez • Edited

Sorry, I cannot help you these days. It would require me to setup the environment and to dig into a documentation I haven't went through in months.

But it seems like an API restriction. I would suggest you to debug/inspect the response object 🐞

By the way: it might be a good idea to use Markdown to format your code snippets 🎨 That makes it easier for other people to help you.

Cheers!

Collapse
 
hafizusman924 profile image
Usman Ali

Thanks for your reply. Could you please take a look whenever you free.

Thread Thread
 
alexkolzov profile image
alexkolzov

Are you solve this problem?