@@ -255,7 +255,7 @@ def _vk_login(self, captcha_sid=None, captcha_key=None):
255255 self .http .cookies .clear ()
256256
257257 # Get cookies
258- response = self .http .get ('https://vk.com/login ' )
258+ response = self .http .get ('https://vk.com/' )
259259
260260 if response .url .startswith ('https://vk.com/429.html?' ):
261261 # is this version still used???
@@ -273,34 +273,39 @@ def _vk_login(self, captcha_sid=None, captcha_key=None):
273273 'Origin' : 'https://vk.com' ,
274274 }
275275
276- values = {
277- 'act' : 'login' ,
278- 'role' : 'al_frame' ,
279- 'expire' : '' ,
280- 'to' : search_re (RE_LOGIN_TO , response .text ),
281- 'recaptcha' : '' ,
282- 'captcha_sid' : '' ,
283- 'captcha_key' : '' ,
284- '_origin' : 'https://vk.com' ,
285- 'utf8' : '1' ,
286- 'ip_h' : search_re (RE_LOGIN_IP_H , response .text ),
287- 'lg_h' : search_re (RE_LOGIN_LG_H , response .text ),
288- 'lg_domain_h' : search_re (RE_LOGIN_LG_DOMAIN_H , response .text ),
289- 'ul' : '' ,
290- 'email' : self .login ,
291- 'pass' : self .password
292- }
276+ for _ in range (8 ): # idk, maybe less is enough
277+ values = {
278+ 'act' : 'login' ,
279+ 'role' : 'al_frame' ,
280+ 'expire' : '' ,
281+ 'to' : search_re (RE_LOGIN_TO , response .text ),
282+ 'recaptcha' : '' ,
283+ 'captcha_sid' : '' ,
284+ 'captcha_key' : '' ,
285+ '_origin' : 'https://vk.com' ,
286+ 'utf8' : '1' ,
287+ 'ip_h' : search_re (RE_LOGIN_IP_H , response .text ),
288+ 'lg_h' : search_re (RE_LOGIN_LG_H , response .text ),
289+ 'lg_domain_h' : search_re (RE_LOGIN_LG_DOMAIN_H , response .text ),
290+ 'ul' : '' ,
291+ 'email' : self .login ,
292+ 'pass' : self .password
293+ }
293294
294- if captcha_sid and captcha_key :
295- self .logger .info (f'Using captcha code: { captcha_sid } : { captcha_key } ' )
296- values ['captcha_sid' ] = captcha_sid
297- values ['captcha_key' ] = captcha_key
295+ if captcha_sid and captcha_key :
296+ self .logger .info (f'Using captcha code: { captcha_sid } : { captcha_key } ' )
297+ values ['captcha_sid' ] = captcha_sid
298+ values ['captcha_key' ] = captcha_key
298299
299- response = self .http .post (
300- 'https://login.vk.com/?act=login' ,
301- data = values ,
302- headers = headers
303- )
300+ response = self .http .post (
301+ 'https://login.vk.com/?act=login' , data = values , headers = headers )
302+ if 'onLoginFailed(7,' in response .text :
303+ response = self .http .get ('https://vk.com/login?m=7' )
304+ time .sleep (0.2 )
305+ continue
306+ if 'onLoginDone(' in response .text :
307+ self .logger .info ('Found "LoginDone"' )
308+ break
304309
305310 response = self ._check_challenge (response )
306311
@@ -320,7 +325,7 @@ def _vk_login(self, captcha_sid=None, captcha_key=None):
320325
321326 return self .error_handlers [CAPTCHA_ERROR_CODE ](captcha )
322327
323- if 'onLoginFailed(4' in response .text :
328+ if 'onLoginFailed(4, ' in response .text :
324329 raise BadPassword ('Bad password' )
325330
326331 if 'act=authcheck' in response .text :
@@ -367,9 +372,7 @@ def _pass_twofactor(self, auth_response, captcha_sid=None, captcha_key=None):
367372 values ['captcha_key' ] = captcha_key
368373
369374 response = self .http .post (
370- 'https://vk.com/al_login.php?act=a_authcheck_code' ,
371- values
372- )
375+ 'https://vk.com/al_login.php?act=a_authcheck_code' , values )
373376 data = json .loads (response .text .lstrip ('<!--' ))
374377 status = data ['payload' ][0 ]
375378
@@ -483,7 +486,6 @@ def _api_login(self):
483486 if url :
484487 response = self .http .get (url )
485488 elif 'redirect_uri' in response .url :
486- response = self .http .get (response .url )
487489 auth_json = json .loads (search_re (RE_AUTH_TOKEN_URL , response .text ))
488490 return_auth_hash = auth_json ['data' ]['hash' ]['return_auth' ]
489491 response = self .http .post (
0 commit comments