-
Notifications
You must be signed in to change notification settings - Fork 323
vk_api.exceptions.AuthError: Unknown error (AUTH; no sid) #522
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dc19998
Новая форма логина
kyzima-spb 68a236d
Испралвена ошибка с капчей для login.vk.com и добавлен метод для рабо…
kyzima-spb 0f51f82
Добавил в исключение ссылку на изображение капчи
kyzima-spb efd2909
Рефакторинг функции generate_device_id
kyzima-spb c947eae
Исправлена ошибка с отсутствием next_step для некоторых аккаунтов
kyzima-spb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| """ | ||
| :authors: python273, kyzima-spb | ||
| :license: Apache License, Version 2.0, see LICENSE file | ||
|
|
||
| :copyright: (c) 2019 python273 | ||
| """ | ||
|
|
||
| import json | ||
| import re | ||
| import typing as t | ||
|
|
||
| import requests | ||
|
|
||
| from .exceptions import ParseError | ||
| from .utils import ( | ||
| set_cookies_from_list, | ||
| generate_device_id, | ||
| search_re, | ||
| ) | ||
|
|
||
|
|
||
| __all__ = ( | ||
| 'WebLoginCredentials', | ||
| ) | ||
|
|
||
|
|
||
| class WebLoginCredentials: | ||
| """ | ||
| Парсит и хранит данные новой формы входа, | ||
| нужные для процесса аутентификации и авторизации пользователя. | ||
| """ | ||
|
|
||
| SIGNIN_URL = 'https://m.vk.com/join?vkid_auth_type=sign_in' | ||
| DEFAULT_COOKIES = [ | ||
| { # если не установлено, то не будет редирект на страницу с данными аутентификации | ||
| 'version': 0, | ||
| 'name': 'remixmdevice', | ||
| 'value': '1920/1080/2/!!-!!!!', | ||
| 'port': None, | ||
| 'port_specified': False, | ||
| 'domain': '.vk.com', | ||
| 'domain_specified': True, | ||
| 'domain_initial_dot': True, | ||
| 'path': '/', | ||
| 'path_specified': True, | ||
| 'secure': True, | ||
| 'expires': None, | ||
| 'discard': False, | ||
| 'comment': None, | ||
| 'comment_url': None, | ||
| 'rfc2109': False, | ||
| 'rest': {} | ||
| } | ||
| ] | ||
|
|
||
| def __init__( | ||
| self, | ||
| session: requests.Session, | ||
| api_version: str = '5.207', | ||
| ) -> None: | ||
| set_cookies_from_list(session.cookies, self.DEFAULT_COOKIES) | ||
|
|
||
| response = session.get(self.SIGNIN_URL) | ||
| pattern = re.compile(r'window\.init\s*=\s*({.*?});', re.DOTALL) | ||
| json_config = search_re(pattern, response.text) | ||
|
|
||
| if json_config is None: | ||
| raise ParseError('Failed to get the value of variable window.init.') | ||
|
|
||
| self._config = json.loads(json_config) | ||
|
|
||
| self.sid = '' | ||
| self.can_skip_password = False | ||
|
|
||
| self.device_id = generate_device_id() | ||
| self.api_version = api_version | ||
|
|
||
| @property | ||
| def app_id(self) -> str: | ||
| """ID приложения, через которое выполняется вход.""" | ||
| return self._config['auth']['host_app_id'] | ||
|
|
||
| @property | ||
| def uuid(self) -> str: | ||
| """ | ||
| Уникальный идентификатор запроса. | ||
|
|
||
| (вероятно, временный для конкретного входа). | ||
| """ | ||
| return self._config['data']['uuid'] | ||
|
|
||
| @property | ||
| def access_token(self) -> str: | ||
| """Токен доступа.""" | ||
| return self._config['auth']['access_token'] | ||
|
|
||
| @property | ||
| def anonymous_token(self) -> str: | ||
| """Анонимный токен доступа.""" | ||
| return self._config['auth']['anonymous_token'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не думаю нужно отдельные ошибки, можно просто AuthError. Смысл отдельные добавлять только если их обрабатывать как-то можно
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AuthErrorбазовый тип, к нему по логике не возможно добавить какую-то дополнительную информацию об ошибке. Вызовы к login возвращают стандартизированный ответ, в котором естьerror_codeи другая информация об ошибке. Я думаю могут быть ситуации, когда пользователю библиотеки эта информация пригодится =)ParseErrorвозможно действительно лишний. В любом случае позже я хочу добавить вход по qr-коду и посмотрю свежим взглядом, пусть пока "полежит" =)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Такое можно просто в текст ошибки, обрабатывать это все равно норм не получится. Можно конечно в AuthError добавить поле для какой-то общей error_metadata и туда сувать всякое, но тоже не уверен есть ли смысл