Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random error while decrypting database #12

Closed
xxxwww opened this issue Dec 27, 2018 · 4 comments · Fixed by #29
Closed

Random error while decrypting database #12

xxxwww opened this issue Dec 27, 2018 · 4 comments · Fixed by #29
Assignees
Labels
bug Something isn't working

Comments

@xxxwww
Copy link

xxxwww commented Dec 27, 2018

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

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 <module>
    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'}}

@alexander-akhmetov alexander-akhmetov self-assigned this Dec 27, 2018
@tomtao007
Copy link

hello, can you resolve this issues? how to ?

@peterus
Copy link
Contributor

peterus commented Mar 21, 2019

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

@alexander-akhmetov alexander-akhmetov added the bug Something isn't working label Apr 5, 2019
@alexander-akhmetov
Copy link
Owner

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
Copy link
Owner

alexander-akhmetov commented Apr 5, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants