Skip to content

Commit

Permalink
[fixed] Login did not work because the captcha on the Kobo store's lo…
Browse files Browse the repository at this point in the history
…gin page has been changed from reCAPTCHA to hCaptcha.
  • Loading branch information
TnS-hun committed Apr 12, 2022
1 parent 902b8f1 commit 895d2a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 8 additions & 2 deletions kobo-book-downloader/Kobo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -182,7 +187,8 @@ def Login( self, email: str, password: str, captcha: str ) -> None:
"__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 )
Expand Down
8 changes: 4 additions & 4 deletions kobo-book-downloader/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def InitializeKoboApi() -> None:
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 ); }
} );
Expand Down

0 comments on commit 895d2a2

Please sign in to comment.