alexander-akhmetov / python-telegram

Python client for the Telegram's tdlib
MIT License
610 stars 122 forks source link

Random error while decrypting database #12

Closed xxxwww closed 5 years ago

xxxwww commented 5 years ago

Regular class initialization

client = Telegram(
    api_id=self.api_id,
    api_hash=self.api_hash,
    library_path=self.library_path,
    phone='+XXXXXXXXXXXX'',
    database_encryption_key='XXXXXXXXXXX',
    use_test_dc=True,
    files_directory=self.files_directory,
    use_message_database=False,
    login=True,
)

Randomly causes an error

Telegram error: {'@type': 'error', 'code': 401, 'message': 'Database encryption key is needed: call checkDatabaseEncryptionKey first', '@extra': {'request_id': 'updateAuthorizationState'}}

Next time you start everything can work fine

Full log

```python INFO:telegram.tdjson:Using shared library "/app/telegram_data/vendor/tdlib/libtdjson.so" INFO:telegram.client:[Telegram.td_listener] started INFO:telegram.worker:[SimpleWorker] started INFO:telegram.client:[login] Login process has been started INFO:telegram.client:[login] current authorization state: None INFO:telegram.client:Setting tdlib initial params: files_dir=/app/telegram_data/data/ test_dc=True DEBUG:telegram.tdjson:[me ==>] Sent b'{"@type": "setTdlibParameters", "parameters": {"use_test_dc": true, "api_id": API_ID, "api_hash": "API_HASH", "device_model": "python-telegram", "system_version": "unknown", "application_version": "0.7.0", "system_language_code": "en", "database_directory": "/app/telegram_data/data/database", "use_message_database": false, "files_directory": "/app/telegram_data/data/files"}, "@extra": {"request_id": "updateAuthorizationState"}}' DEBUG:telegram.tdjson:[me <==] Received {'@type': 'updateAuthorizationState', 'authorization_state': {'@type': 'authorizationStateWaitTdlibParameters'}} DEBUG:telegram.tdjson:[me <==] Received {'@type': 'updateAuthorizationState', 'authorization_state': {'@type': 'authorizationStateWaitEncryptionKey', 'is_encrypted': True}} DEBUG:telegram.client:async_result has not been found in by request_id=updateAuthorizationState DEBUG:telegram.tdjson:[me <==] Received {'@type': 'ok', '@extra': {'request_id': 'updateAuthorizationState'}} DEBUG:telegram.client:async_result has not been found in by request_id=updateAuthorizationState INFO:telegram.client:[login] current authorization state: authorizationStateWaitTdlibParameters INFO:telegram.client:Setting tdlib initial params: files_dir=/app/telegram_data/data/ test_dc=True DEBUG:telegram.tdjson:[me ==>] Sent b'{"@type": "setTdlibParameters", "parameters": {"use_test_dc": true, "api_id": API_ID, "api_hash": "API_HASH", "device_model": "python-telegram", "system_version": "unknown", "application_version": "0.7.0", "system_language_code": "en", "database_directory": "/app/telegram_data/data/database", "use_message_database": false, "files_directory": "/app/telegram_data/data/files"}, "@extra": {"request_id": "updateAuthorizationState"}}' DEBUG:telegram.tdjson:[me <==] Received {'@type': 'error', 'code': 401, 'message': 'Database encryption key is needed: call checkDatabaseEncryptionKey first', '@extra': {'request_id': 'updateAuthorizationState'}} Traceback (most recent call last): File "manage.py", line 15, in execute_from_command_line(sys.argv) File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line utility.execute() File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 316, in run_from_argv self.execute(*args, **cmd_options) File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 353, in execute output = self.handle(*args, **options) File "/app/telegram_data/management/commands/test.py", line 38, in handle login=True, File "/usr/local/lib/python3.7/site-packages/telegram/client.py", line 90, in __init__ self.login() File "/usr/local/lib/python3.7/site-packages/telegram/client.py", line 339, in login result.wait(raise_exc=True) File "/usr/local/lib/python3.7/site-packages/telegram/utils.py", line 39, in wait raise RuntimeError(f'Telegram error: {self.error_info}') RuntimeError: Telegram error: {'@type': 'error', 'code': 401, 'message': 'Database encryption key is needed: call checkDatabaseEncryptionKey first', '@extra': {'request_id': 'updateAuthorizationState'}} ```

tomtao007 commented 5 years ago

hello, can you resolve this issues? how to ?

peterus commented 5 years ago

With last Version 0.8.0 the issues are not so often anymore, but still be seen.

alexander-akhmetov commented 5 years ago

As I see in the logs, the library sent setTdlibParameters twice. Probably, this is why the problem happens. I will try to release a fix soon.

alexander-akhmetov commented 5 years ago

Should be fixed in version 0.9.0. Please, reopen the issue if you will have the same problem.