TnS-hun / kobo-book-downloader

A tool to download your purchased Kobo books and remove the DRM from them.
The Unlicense
257 stars 63 forks source link

KeyError: 'TokenType' - refresh authentication credentials #28

Open valeriedcwu opened 2 days ago

valeriedcwu commented 2 days ago

I love this downloader, and it worked perfectly for me last year. However, after a year when I tried to run the program, I had token issues as follows. Therefore, I am wondering if we can refresh the authentication credentials in the interactive commanding surface. Thank you.

Traceback (most recent call last): File "C:\ProgramData\Anaconda3\lib\runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\ProgramData\Anaconda3\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "kobo-book-downloader__main.py", line 98, in Main() File "kobo-book-downloader\main.py", line 85, in Main InitializeKoboApi() File "kobo-book-downloader\main__.py", line 26, in InitializeKoboApi Globals.Kobo.LoadInitializationSettings() File "kobo-book-downloader\Kobo.py", line 156, in LoadInitializationSettings response = self.Session.get( "https://storeapi.kobo.com/v1/initialization", headers = headers, hooks = hooks ) File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 555, in get return self.request('GET', url, kwargs) File "kobo-book-downloader\Kobo.py", line 55, in request return super().request( method, url, kwargs ) File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 542, in request resp = self.send(prep, send_kwargs) File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 662, in send r = dispatch_hook('response', hooks, r, kwargs) File "C:\ProgramData\Anaconda3\lib\site-packages\requests\hooks.py", line 31, in dispatch_hook _hook_data = hook(hook_data, **kwargs) File "kobo-book-downloader\Kobo.py", line 37, in ReauthenticationHook Globals.Kobo.RefreshAuthentication() File "kobo-book-downloader\Kobo.py", line 141, in RefreshAuthentication if jsonResponse[ "TokenType" ] != "Bearer": KeyError: 'TokenType'

TnS-hun commented 2 days ago

Currently there is no built-in command to log in again.

Run the kobo-book-downloader info command to see the location of the configuration file. Delete that file, and then run kobo-book-downloader normally and it will ask for login.

valeriedcwu commented 1 day ago

Oh then probably there's another issue. I tried, and the program asked for login again. However, I got the 403 forbidden access. Did kobo change its API or something else?

Traceback (most recent call last): File "C:\ProgramData\Anaconda3\lib\runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\ProgramData\Anaconda3\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "kobo-book-downloader__main.py", line 98, in Main() File "kobo-book-downloader\main.py", line 85, in Main InitializeKoboApi() File "kobo-book-downloader\main.py", line 54, in InitializeKoboApi Globals.Kobo.Login( email, password, captcha ) File "kobo-book-downloader\Kobo.py", line 197, in Login signInUrl, workflowId, requestVerificationToken = self.GetExtraLoginParameters() File "kobo-book-downloader\Kobo.py", line 174, in __GetExtraLoginParameters response.raise_for_status() File "C:\ProgramData\Anaconda3\lib\site-packages\requests\models.py", line 943, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://authorize.kobo.com/signin?returnUrl=http://kobo.com/&wsa=Kobo&pwsav=8.11.24971&pwspid=00000000-0000-0000-0000-000000004000&pwsdid=c0bc226f-0342-4e7d-9f06-41ef8441196a

TnS-hun commented 1 day ago

I could reproduce the problem. I will look into it.