2424TWOFACTOR_CODE = - 2
2525
2626RE_LOGIN_HASH = re .compile (r'name="lg_h" value="([a-z0-9]+)"' )
27- RE_CAPTCHAID = re .compile (r'sid= (\d+)' )
27+ RE_CAPTCHAID = re .compile (r"onLoginCaptcha\(' (\d+)'" )
2828RE_NUMBER_HASH = re .compile (r"al_page: '3', hash: '([a-z0-9]+)'" )
2929RE_AUTH_HASH = re .compile (r"hash: '([a-z_0-9]+)'" )
3030RE_TOKEN_URL = re .compile (r'location\.href = "(.*?)"\+addr;' )
@@ -120,7 +120,7 @@ def authorization(self, reauth=False):
120120 if not self .check_sid ():
121121 self .vk_login ()
122122 else :
123- self .security_check ('https://vk.com/settings' )
123+ self .security_check ()
124124
125125 if not self .check_token ():
126126 self .api_login ()
@@ -152,7 +152,7 @@ def vk_login(self, captcha_sid=None, captcha_key=None):
152152
153153 remixsid = None
154154
155- if 'act=authcheck' in response .url :
155+ if 'act=authcheck' in response .url : # TODO: test/fix
156156 code , remember_device = self .error_handlers [TWOFACTOR_CODE ]()
157157 response = self .twofactor (response , code , remember_device )
158158
@@ -174,8 +174,8 @@ def vk_login(self, captcha_sid=None, captcha_key=None):
174174
175175 self .sid = remixsid
176176
177- elif 'sid= ' in response .url :
178- captcha_sid = search_re (RE_CAPTCHAID , response .url )
177+ elif 'onLoginCaptcha( ' in response .text :
178+ captcha_sid = search_re (RE_CAPTCHAID , response .text )
179179 captcha = Captcha (self , captcha_sid , self .vk_login )
180180
181181 if self .error_handlers [CAPTCHA_ERROR_CODE ]:
@@ -185,12 +185,13 @@ def vk_login(self, captcha_sid=None, captcha_key=None):
185185 elif 'onLoginFailed(4' in response .text :
186186 raise BadPassword ('Bad password' )
187187 else :
188- raise AuthorizationError ('Unknown error. Please send bugreport.' )
188+ raise AuthorizationError (
189+ 'Unknown error. Please send bugreport: https://vk.com/python273'
190+ )
189191
190- if 'security_check' in response .url :
191- self .security_check (response = response )
192+ self .security_check ()
192193
193- if 'act=blocked' in response .url :
194+ if 'act=blocked' in response .url : # TODO: text/fix
194195 raise AccountBlocked ('Account is blocked' )
195196
196197 def twofactor (self , response , code , remember_device = False ):
@@ -221,9 +222,9 @@ def twofactor(self, response, code, remember_device=False):
221222 return response
222223 raise TwoFactorError ('Incorrect code: %s' % code )
223224
224- def security_check (self , url = None , response = None ):
225- if url :
226- response = self .http .get (url )
225+ def security_check (self , response = None ):
226+ if response is None :
227+ response = self .http .get ('https://vk.com/settings' )
227228 if 'security_check' not in response .url :
228229 return
229230
0 commit comments