Эх сурвалжийг харах

[fixed] Login did not work because the captcha on the Kobo store's login page has been changed from reCAPTCHA to hCaptcha.

TnS-hun 3 жил өмнө
parent
commit
895d2a2cb5

+ 8 - 2
kobo-book-downloader/Kobo.py

@@ -56,9 +56,14 @@ class Kobo:
 	DisplayProfile = "Android"
 
 	def __init__( self ):
+		# Use the user agent of the Kobo Android app, otherwise the login request hangs forever.
+		headers = {
+			"User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Google Nexus 7 2013 Build/MRA58K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/74.0.3729.186 Safari/537.36 KoboApp/8.40.2.29861 KoboPlatform Id/00000000-0000-0000-0000-000000004000 KoboAffiliate/Kobo KoboBuildFlavor/global",
+		}
+
 		self.InitializationSettings = {}
 		self.Session = SessionWithTimeOut()
-		self.Session.headers.update( { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0" } )
+		self.Session.headers.update( headers )
 
 	# This could be added to the session but then we would need to add { "Authorization": None } headers to all other
 	# functions that doesn't need authorization.
@@ -182,7 +187,8 @@ class Kobo:
 			"__RequestVerificationToken": requestVerificationToken,
 			"LogInModel.UserName": email,
 			"LogInModel.Password": password,
-			"g-recaptcha-response": captcha
+			"g-recaptcha-response": captcha,
+			"h-captcha-response": captcha
 		}
 
 		response = self.Session.post( signInUrl, data = postData )

+ 4 - 4
kobo-book-downloader/__main__.py

@@ -25,10 +25,10 @@ loads (do not login!) then open the developer tools (use F12 in Firefox/Chrome),
 and paste the following code there and then press Enter there in the browser.
 
 var newCaptchaDiv = document.createElement( "div" );
-newCaptchaDiv.id = "new-grecaptcha-container";
-document.getElementById( "grecaptcha-container" ).insertAdjacentElement( "afterend", newCaptchaDiv );
-grecaptcha.render( newCaptchaDiv.id, {
-	sitekey: "6LeEbUwUAAAAADJxtlhMsvgnR7SsFpMm4sirr1CJ",
+newCaptchaDiv.id = "new-hcaptcha-container";
+document.getElementById( "hcaptcha-container" ).insertAdjacentElement( "afterend", newCaptchaDiv );
+hcaptcha.render( newCaptchaDiv.id, {
+	sitekey: "51a1773a-a9ae-4992-a768-e3b8d87355e8",
 	callback: function( response ) { console.log( "Captcha response:" ); console.log( response ); }
 } );