prawn-cake / vk-requests

vk.com requests for humans. API library for vk.com
MIT License
158 stars 22 forks source link

Example of get_captcha_key method reloading #2

Closed hograthm closed 8 years ago

hograthm commented 8 years ago

I'm new to Python and do not quite understand how I have to reload this method in my code to handle captcha. It would be nice to see an example.

prawn-cake commented 8 years ago

The get_captcha_key is a part of BaseAuthAPI sub-classes which are part of VKSession namely VKSession.AUTH_API_CLS class variable.

To override the method you need:

class MyAuthAPI(BaseAuthAPI):
    def get_captcha_key(self):
        # do something

class MyVKSession(VKSession):
    AUTH_API_CLS = MyAuthAPI

# Copied from create_api method
session = MyVKSession(app_id, login, password, phone_number=phone_number,
                                       scope=scope, api_version=api_version)
api = API(session=session, timeout=timeout, **method_default_args)

Well, I see that it's a bit hassle to do it and adding auth_api_cls as an instance parameter would be reasonable. I will think about it

hograthm commented 8 years ago

Thanks a lot.