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 ()
@@ -134,7 +134,8 @@ def vk_login(self, captcha_sid=None, captcha_key=None):
134134 response = self .http .get ('https://vk.com/' )
135135
136136 values = {
137- 'act' : 'login' ,
137+ 'role' : 'al_frame' ,
138+ '_origin' : 'https://vk.com' ,
138139 'utf8' : '1' ,
139140 'email' : self .login ,
140141 'pass' : self .password ,
@@ -147,11 +148,11 @@ def vk_login(self, captcha_sid=None, captcha_key=None):
147148 'captcha_key' : captcha_key
148149 })
149150
150- response = self .http .post ('https://login.vk.com/' , values )
151+ response = self .http .post ('https://login.vk.com/?act=login ' , values )
151152
152153 remixsid = None
153154
154- if 'act=authcheck' in response .url :
155+ if 'act=authcheck' in response .url : # TODO: test/fix
155156 code , remember_device = self .error_handlers [TWOFACTOR_CODE ]()
156157 response = self .twofactor (response , code , remember_device )
157158
@@ -173,23 +174,24 @@ def vk_login(self, captcha_sid=None, captcha_key=None):
173174
174175 self .sid = remixsid
175176
176- elif 'sid= ' in response .url :
177- captcha_sid = search_re (RE_CAPTCHAID , response .url )
177+ elif 'onLoginCaptcha( ' in response .text :
178+ captcha_sid = search_re (RE_CAPTCHAID , response .text )
178179 captcha = Captcha (self , captcha_sid , self .vk_login )
179180
180181 if self .error_handlers [CAPTCHA_ERROR_CODE ]:
181182 return self .error_handlers [CAPTCHA_ERROR_CODE ](captcha )
182183 else :
183184 raise AuthorizationError ('Authorization error (capcha)' )
184- elif 'm=1 ' in response .url :
185+ elif 'onLoginFailed(4 ' in response .text :
185186 raise BadPassword ('Bad password' )
186187 else :
187- raise AuthorizationError ('Unknown error. Please send bugreport.' )
188+ raise AuthorizationError (
189+ 'Unknown error. Please send bugreport: https://vk.com/python273'
190+ )
188191
189- if 'security_check' in response .url :
190- self .security_check (response = response )
192+ self .security_check ()
191193
192- if 'act=blocked' in response .url :
194+ if 'act=blocked' in response .url : # TODO: text/fix
193195 raise AccountBlocked ('Account is blocked' )
194196
195197 def twofactor (self , response , code , remember_device = False ):
@@ -220,9 +222,9 @@ def twofactor(self, response, code, remember_device=False):
220222 return response
221223 raise TwoFactorError ('Incorrect code: %s' % code )
222224
223- def security_check (self , url = None , response = None ):
224- if url :
225- 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' )
226228 if 'security_check' not in response .url :
227229 return
228230
0 commit comments