mikf / gallery-dl

Command-line program to download image galleries and collections from several image hosting sites
GNU General Public License v2.0
11.89k stars 976 forks source link

[redgifs] Failed to get Bearer token due to concatenation error #3080

Closed slowthgt closed 2 years ago

slowthgt commented 2 years ago

A follow-up from https://github.com/mikf/gallery-dl/issues/3037

Tested with current release and latest CI.

Could be that the text.extract is not functioning properly?


[gallery-dl][debug] Version 1.23.3 - Executable
[gallery-dl][debug] Python 3.7.9 - Windows-10-10.0.19041
[gallery-dl][debug] requests 2.28.1 - urllib3 1.26.12
[gallery-dl][debug] Starting DownloadJob for 'https://redgifs.com/watch/foolishforkedabyssiniancat'
[redgifs][debug] Using RedgifsImageExtractor for 'https://redgifs.com/watch/foolishforkedabyssiniancat'
[redgifs][debug] Retrieving Bearer token
[urllib3.connectionpool][debug] Starting new HTTPS connection (1): www.redgifs.com:443
[urllib3.connectionpool][debug] https://www.redgifs.com:443 "GET / HTTP/1.1" 200 None
[urllib3.connectionpool][debug] https://www.redgifs.com:443 "GET /assets/js/index.5da1b193.js HTTP/1.1" 200 None
[redgifs][error] An unexpected error occurred: TypeError - can only concatenate str (not "NoneType") to str. Please run gallery-dl again with the --verbose flag, copy its output and report this issue on https://github.com/mikf/gallery-dl/issues .
[redgifs][debug]
Traceback (most recent call last):
  File "gallery_dl\job.pyc", line 82, in run
  File "gallery_dl\extractor\redgifs.pyc", line 36, in items
  File "gallery_dl\extractor\redgifs.pyc", line 127, in gifs
  File "gallery_dl\extractor\redgifs.pyc", line 137, in __init__
  File "gallery_dl\cache.pyc", line 115, in __call__
  File "gallery_dl\extractor\redgifs.pyc", line 182, in _fetch_bearer_token
TypeError: can only concatenate str (not "NoneType") to str
chio0hai commented 2 years ago

It's just RedGifs changing their api again.

The following works for me:

--- a/gallery_dl/extractor/redgifs.py
+++ b/gallery_dl/extractor/redgifs.py
@@ -174,12 +174,7 @@ class RedgifsAPI():
     def _fetch_bearer_token(self, extr):
         extr.log.debug("Retrieving Bearer token")

-        page = extr.request(extr.root + "/").text
-        index = text.extract(page, "/assets/js/index", ".js")[0]
-
-        url = extr.root + "/assets/js/index" + index + ".js"
-        page = extr.request(url, encoding="utf-8").text
-        token = "ey" + text.extract(page, '="ey', '"')[0]
+        token = extr.request(self.API_ROOT + '/v2/auth/temporary').json()['token']

         extr.log.debug("Token: '%s'", token)
         return token