vkpymusic.TokenReceiverAsync
A class that is responsible for performing authorization using the available login and password. It interacts with the VK API to obtain an access token. WARNING!!! The TokenReceiverAsync class DOESN'T provide methods for handling captcha, 2-factor authentication, and various error scenarios. You need to implement them yourself using the appropriate handlers.
Attributes:
Name | Type | Description |
---|---|---|
client |
Client
|
The client object. |
__login |
str
|
The login. |
__password |
str
|
The password. |
__token |
str
|
The token. |
_logger |
Logger
|
The logger. |
Example usage:
>>> import asyncio
>>> from vkpymusic import TokenReceiverAsync
>>>
>>> receiver = TokenReceiverAsync(login="my_username", password="my_password")
>>> if asyncio.run(receiver.auth()):
... receiver.get_token()
... receiver.save_to_config()
Functions
__init__(login, password, client='Kate', logger=create_logger(__name__))
Initialize TokenReceiver.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
login
|
str
|
Login to VK. |
required |
password
|
str
|
Password to VK. |
required |
client
|
str
|
Client to VK (default value = "Kate"). |
'Kate'
|
logger
|
Logger
|
Logger (default value = my logger). |
create_logger(__name__)
|
request_auth(code=None, captcha=None)
async
Request auth from VK.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code
|
Optional[str]
|
Code from VK/SMS (default value = None). |
None
|
captcha
|
Optional[Tuple[str, str]]
|
Captcha (default value = None). |
None
|
Returns:
Name | Type | Description |
---|---|---|
Response |
Response
|
Response from VK. |
request_code(sid)
async
Request code from VK.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sid
|
Union[str, int]
|
Sid from VK. |
required |
Returns:
Name | Type | Description |
---|---|---|
Response |
Response
|
Response from VK. |
auth(on_captcha, on_2fa, on_invalid_client, on_critical_error)
async
Performs ASYNC authorization using the available login and password. If necessary, interactively accepts a code from SMS or captcha.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
on_captcha
|
Callable[[str], str]
|
ASYNC handler to captcha. Get url image. Return key. |
required |
on_2fa
|
Callable[[], str]
|
ASYNC handler to 2-factor auth. Return captcha. |
required |
on_invalid_client
|
Callable[[], None]
|
ASYNC handler to invalid client. |
required |
on_critical_error
|
Callable[[Any], None]
|
ASYNC handler to crit error. Get response. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Boolean value indicating whether authorization was successful or not. |
get_token()
Prints token in console (if authorisation was successful).
save_to_config(file_path='config_vk.ini')
Save token and user agent data in config (if authorisation was succesful).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
Filename of config (default value = "config_vk.ini"). |
'config_vk.ini'
|
create_path(file_path)
staticmethod
Create path before and after this for different funcs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
Relative path to file. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Absolute path to file. |