prawn-cake / vk-requests

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

Problem with 2-step auth #14

Closed ghost closed 8 years ago

ghost commented 8 years ago

Что происходит

2016-11-11 21:05:55,719 INFO [vk-requests] User enabled 2 factors authorization. Auth check code is needed
2016-11-11 21:05:55,734 DEBUG [vk-requests] Action url /login?act=authcheck_code&hash=1478887555_ff181e72e9db30cbc3
Auth check code: 241350
2016-11-11 21:06:04,409 DEBUG [vk-requests] Request: POST /login?act=authcheck_code&hash=1478887555_ff181e72e9db30cbc3, params=None, data={'code': '241350', '_ajax': '1', 'remember': '1'}
Traceback (most recent call last):
  File "lyc.py", line 28, in <module>
    api = vk.create_api(login='***', password='***', app_id='***', session_cls=ExtendedVKSession)
  File "/usr/local/lib/python3.5/dist-packages/vk_requests-0.9.6-py3.5.egg/vk_requests/__init__.py", line 31, in create_api
  File "/usr/local/lib/python3.5/dist-packages/vk_requests-0.9.6-py3.5.egg/vk_requests/auth.py", line 368, in __init__
  File "/usr/local/lib/python3.5/dist-packages/vk_requests-0.9.6-py3.5.egg/vk_requests/auth.py", line 390, in get_auth_api
  File "lyc.py", line 10, in __init__
    super().__init__(**kwargs)
  File "/usr/local/lib/python3.5/dist-packages/vk_requests-0.9.6-py3.5.egg/vk_requests/auth.py", line 47, in __init__
  File "/usr/local/lib/python3.5/dist-packages/vk_requests-0.9.6-py3.5.egg/vk_requests/auth.py", line 84, in renew_access_token
  File "lyc.py", line 18, in get_access_token
    access_token = super().get_access_token()
  File "/usr/local/lib/python3.5/dist-packages/vk_requests-0.9.6-py3.5.egg/vk_requests/auth.py", line 126, in get_access_token
  File "/usr/local/lib/python3.5/dist-packages/vk_requests-0.9.6-py3.5.egg/vk_requests/auth.py", line 168, in do_login
  File "/usr/local/lib/python3.5/dist-packages/vk_requests-0.9.6-py3.5.egg/vk_requests/auth.py", line 234, in require_sms_code
  File "/usr/local/lib/python3.5/dist-packages/requests-2.11.1-py3.5.egg/requests/sessions.py", line 522, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/vk_requests-0.9.6-py3.5.egg/vk_requests/utils.py", line 149, in request
  File "/usr/local/lib/python3.5/dist-packages/requests-2.11.1-py3.5.egg/requests/sessions.py", line 461, in request
    prep = self.prepare_request(req)
  File "/usr/local/lib/python3.5/dist-packages/requests-2.11.1-py3.5.egg/requests/sessions.py", line 394, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/usr/local/lib/python3.5/dist-packages/requests-2.11.1-py3.5.egg/requests/models.py", line 294, in prepare
    self.prepare_url(url, params)
  File "/usr/local/lib/python3.5/dist-packages/requests-2.11.1-py3.5.egg/requests/models.py", line 354, in prepare_url
    raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL '/login?act=authcheck_code&hash=1478887555_ff181e72e9db30cbc3': No schema supplied. Perhaps you meant http:///login?act=authcheck_code&hash=1478887555_ff181e72e9db30cbc3?

Вероятно, ошибка кроется здесь.

Вместо

response = session.post(action_url, data=auth_check_data)

исправить

response = session.post(self.LOGIN_URL + action_url, data=auth_check_data)
prawn-cake commented 8 years ago

Подтверждаю проблему, разбираюсь. Спасибо за репорт

prawn-cake commented 8 years ago

fixed in the v0.9.7

ghost commented 8 years ago

Спасибо. Может лучше сделать так?

from vk_requests.auth import AuthAPI, VKSession

def create_api(app_id=None, login=None, password=None, phone_number=None,
               timeout=10, scope='offline', api_version=None, auth_api_cls=AuthAPI, 
                **method_default_args):

    session = VKSession(app_id=app_id, user_login=login, user_password=password,
                        phone_number=phone_number, auth_api_cls=auth_api_cls,
                        scope=scope, api_version=api_version)
    return API(session=session, timeout=timeout, **method_default_args)