39
39
RE_PHONE_PREFIX = re .compile (r'label ta_r">\+(.*?)<' )
40
40
RE_PHONE_POSTFIX = re .compile (r'phone_postfix">.*?(\d+).*?<' )
41
41
42
- DEFAULT_USERAGENT = 'Mozilla/5.0 (Windows NT 10.0; rv:91 .0) Gecko/20100101 Firefox/91 .0'
42
+ DEFAULT_USERAGENT = 'Mozilla/5.0 (Windows NT 10.0; rv:109 .0) Gecko/20100101 Firefox/115 .0'
43
43
44
44
DEFAULT_USER_SCOPE = sum (VkUserPermissions )
45
45
@@ -188,7 +188,6 @@ def auth(self, reauth=False, token_only=False):
188
188
self ._auth_cookies (reauth = reauth )
189
189
190
190
def _auth_cookies (self , reauth = False ):
191
-
192
191
if reauth :
193
192
self .logger .info ('Auth forced' )
194
193
@@ -213,7 +212,6 @@ def _auth_cookies(self, reauth=False):
213
212
self .logger .info ('access_token from config is valid' )
214
213
215
214
def _auth_token (self , reauth = False ):
216
-
217
215
if not reauth and self ._check_token ():
218
216
self .logger .info ('access_token from config is valid' )
219
217
return
@@ -229,6 +227,16 @@ def _auth_token(self, reauth=False):
229
227
self ._vk_login ()
230
228
self ._api_login ()
231
229
230
+ def _check_challenge (self , response ):
231
+ if not response .url .startswith ('https://vk.com/challenge.html?' ):
232
+ return response
233
+
234
+ hash429 = urllib .parse .parse_qs (response .url .split ('?' , 1 )[- 1 ])['hash429' ][0 ]
235
+ salt = re .search (r"salt\s*=\s*'(.*)'" , response .text ).group (1 )
236
+ hash429_md5 = md5 (hash429 .encode ('ascii' ) + b':' + salt .encode ('ascii' )).hexdigest ()
237
+ response = self .http .get (f'{ response .url } &key={ hash429_md5 } ' )
238
+ return response
239
+
232
240
def _vk_login (self , captcha_sid = None , captcha_key = None ):
233
241
""" Авторизация ВКонтакте с получением cookies remixsid
234
242
@@ -250,10 +258,13 @@ def _vk_login(self, captcha_sid=None, captcha_key=None):
250
258
response = self .http .get ('https://vk.com/login' )
251
259
252
260
if response .url .startswith ('https://vk.com/429.html?' ):
261
+ # is this version still used???
253
262
hash429_md5 = md5 (self .http .cookies ['hash429' ].encode ('ascii' )).hexdigest ()
254
263
self .http .cookies .pop ('hash429' )
255
264
response = self .http .get (f'{ response .url } &key={ hash429_md5 } ' )
256
265
266
+ response = self ._check_challenge (response )
267
+
257
268
headers = {
258
269
'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' ,
259
270
'Accept-Language' : 'en-US,en;q=0.5' ,
@@ -291,6 +302,8 @@ def _vk_login(self, captcha_sid=None, captcha_key=None):
291
302
headers = headers
292
303
)
293
304
305
+ response = self ._check_challenge (response )
306
+
294
307
if 'onLoginCaptcha(' in response .text :
295
308
self .logger .info ('Captcha code is required' )
296
309
0 commit comments