justfoolingaround / animdl

A highly efficient, fast, powerful and light-weight anime downloader and streamer for your favorite anime.
GNU General Public License v3.0
1.33k stars 109 forks source link

[animepahe site error] httpx client failed to get an api responses from animepahe #291

Open Type-Delta opened 1 year ago

Type-Delta commented 1 year ago

Hello, I tried to stream some animes with animepahe as provider and got the following error.

C:\Python39\lib\json\decoder.py:355 in raw_decode                                      
│                                                                                        
│   352 │      try:                                                                     
│   353 │          obj, end = self.scan_once(s, idx)                                    
│   354 │      except StopIteration as err:                                             
│ ❱ 355 │          raise JSONDecodeError("Expecting value", s, err.value) from None     
│   356 │      return obj, end                                                          
│   357
JSONDecodeError: Expecting value: line 1 column 1 (char 0)

so I did some digging and found out that:

in searcher.py line 64 for some reasons session.get() returns html respond instead of expected JSON respond.

def search_animepahe(session, query):
    animepahe_results = session.get( # <- here
        ANIMEPAHE + "api",
        params={"q": query, "m": "search"},
    )
    content = animepahe_results.json()

    for results in content.get("data", []):
        yield {
            "anime_url": ANIMEPAHE + "anime/" + results.get("session"),
            "name": results.get("title"),
        }

and since the respond is in html format, animepahe_results.json() would throw an error because it can't parse html to Python object (dictionary).

what I did to fix this issue is attach header indicates the response type

animepahe_results = session.get( 
     ANIMEPAHE + "api",
     params={"q": query, "m": "search"},
     headers={'accept': 'application/json'} # <- here
)

this fix the problem for me.

I don't know if others has the same problem or not but here is how to fix it. if you're someone who is working on this project please apply this fix to the codebase.

hoped this is useful >.<

PS: It's probably not the best way to fix this problem, if someone got a better idea you can point it out.