Telethon: AttributeError: 'NoneType' object has no attribute 'key_id'

Created on 4 Oct 2017  路  1Comment  路  Source: LonamiWebs/Telethon

Getting the below error for the below code:
from telethon import TelegramClient
import traceback
import json
import time

with open("config.json","r") as fp:
cfg = json.load(fp)
# Use your own values here
api_id = cfg["api_id"]
api_hash = cfg["api_hash"]
phone_number = cfg["phone_number"]
print(api_id,api_hash,phone_number)

client = TelegramClient('some_name', api_id, api_hash)
val = client.connect() # Must return True, otherwise, try again
print(val)
if not client.is_user_authorized():
client.send_code_request(phone_number)
# .sign_in() may raise PhoneNumberUnoccupiedError
# In that case, you need to call .sign_up() to get a new account
client.sign_in(phone_number, input('Enter code: '))
total, messages, senders = client.get_message_history('user')
print(total,messages,senders)
for message in messages:
print(message)

The `client麓 is now ready

from telethon.utils import get_display_name
dialog_count = 1000
dialogs, entities = client.get_dialogs(dialog_count)

Display them so the user can choose

for i, entity in enumerate(entities, start=1):
try:
print('%d. %s|%s|%d'%(i, get_display_name(entity),entity.username,entity.id))
except:
print(entity)

Traceback (most recent call last):
File "telegram_client.py", line 18, in
client.send_code_request(phone_number)
File "C:\Users\IBM_ADMIN\rcs\Miniconda36\Lib\site-packages\telethon\telegram_client.py", line 323, in send_code_request
result = self(SendCodeRequest(phone, self.api_id, self.api_hash))
File "C:\Users\IBM_ADMIN\rcs\Miniconda36\Lib\site-packages\telethon\telegram_client.py", line 265, in invoke
retries=kwargs.get('retries', 5)
File "C:\Users\IBM_ADMIN\rcs\Miniconda36\Lib\site-packages\telethon\telegram_bare_client.py", line 316, in invoke
self._sender.send(*requests)
File "C:\Users\IBM_ADMIN\rcs\Miniconda36\Lib\site-packages\telethonnetwork\mtproto_sender.py", line 80, in send
self._send_message(message)
File "C:\Users\IBM_ADMIN\rcs\Miniconda36\Lib\site-packages\telethonnetwork\mtproto_sender.py", line 130, in _send_message
key_id = struct.pack(' AttributeError: 'NoneType' object has no attribute 'key_id'

invalid

Most helpful comment

I'm not willing to help unless you make this issue look nicer.

>All comments

I'm not willing to help unless you make this issue look nicer.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iranpak picture iranpak  路  3Comments

pazis picture pazis  路  5Comments

JackCloudman picture JackCloudman  路  6Comments

Lerbytech picture Lerbytech  路  5Comments

ksanderer picture ksanderer  路  3Comments