Open MKS2045 opened 2 years ago
It took a while trying to figure out the error, It's not a fetch chapter bug, it's in the way the chapter_list may be initialized, can you tell me how the chapter_list was initialized?
This? The only problem i have is with that method, the other ones works fine.
After debugging and trying some things I discovered that there are some mangas that do not have available a certain translation available (I don't know the reason but apparently is on mangadex side) so it's returning an empty list, thus the error you are getting. To avoid the error try checking that the list length is not 0 i.e
if len(chapter_list) != 0:
for ix, chapter in enumerate(chapter_list):
chapters.append({
"title" : chapter.title,
# your code
.
.
.
else:
continue #continue with the loop
you mean like this? Because i tried it, but it puts the same error... And i notice another problem, it does not return all chapters. In the json where i dump the information just put a few chapters not all, why is that? And sorry if i am irritating with this questions
Can you provide the full error, like the tracebacks and all? For the reason that it doesn't return all the chapters, I think that is because the API stopped serving some things that are copyrighted or not hosted on mangadex (the chapter has an external link). You can access all the chapters available on the index with api.get_manga_volumes_and_chapters(manga_id = manga_id)
and it will return the chapters available
Okay so this is the full error ig:
And whats the difference between get_manga_volumnes_and_chapters and the chapter_list?
So i think im just dumb.... it appears that i was doing that inside the for loop... sorry for waisting your time with that. I just have the last question about how to use the method get_manga_volumes Because i get all the json stuff but i dont know how to access it to get the links, or name....
I tried to replicate your issue with the following code:
import mangadex
api = mangadex.Api()
random_manga_list = [api.random_manga() for _ in range(10)]
for ix, manga in enumerate(random_manga_list):
chapt_list = api.chapter_list(manga = manga.manga_id, translatedLanguage=['en'])
chapters = []
if chapt_list != 0:
for jx, chap in enumerate(chapt_list):
chapters.append({"Chapter" : {
"title" : chap.title,
"lang": chap.translatedLanguage,
"chaps": chap.fetch_chapter_images()
}})
but couldn't. I have no idea what is causing the problem.
the difference between get_manga_volumes_and_chapters
and chapter_list
, is that the first gives you just the chapter ids of just a manga and chapter_list
will give you from different mangas if you do not pass arguments or pass an array with manga_ids.
EDIT: I just saw your reply. Don't worry about the questions asked, it's ok to ask. As for the other question I wrote something about the explanation of how they differ, with get_manga_volumes_and_chapters
at the moment, you can only get the ids of the chapters (may implement a full chapter list as a return later and if you want you can help!).
So, the thing is to use the method get_chapter with the id that returns the mehod get_manga_volumes_and_chapters? But it seems it returns more than just the id Like the count or others, how can i pick just the id of the chapter? And why the other method that is chapter_list not returning the same? Because the other one is more simple and more easy to use in my opinion And i really wanna help because i found this api very useful, but my knowledge of english and python are quite low... And thank you very much for your help, I appreciate that you respond so quickly
The chapter_list
method returns a List[Chapter]
a list of chapter objects, currently, the get_manga_volumes_and_chapters
just returns a JSON. The main reason that this returns a JSON is that I haven't parsed them into a Chapter object, and the way the JSON is constructed prevents me from using the Chapter.ChapterFromDIct
constructor that I have implemented. Just use the method that works best for you, I have the method because the API offers it.
For the contribution part, it occurs to me that as a challenge you try to convert this JSON into a list of Chapters, you don't have to submit but I'll be glad if you send me your solution (And it may end up in the library). If you have any more questions, feel free to ask.
You mean like this?
And also i have another question, how can i do to generate multiple manga and not to fail with the type error:
Traceback (most recent call last): File "c:\Users\Wiliam1\Documents\proyectoFinal\yugen\lib\helpers\api\api2.py", line 50, in <module> "images" : chapter.fetch_chapter_images() File "C:\Users\Wiliam1\AppData\Local\Programs\Python\Python310\lib\site-packages\mangadex\models.py", line 213, in fetch_chapter_images image_server_url = URLRequest.request_url(url, "GET", timeout=5) File "C:\Users\Wiliam1\AppData\Local\Programs\Python\Python310\lib\site-packages\mangadex\url_models.py", line 59, in request_url raise ApiError(resp) File "C:\Users\Wiliam1\AppData\Local\Programs\Python\Python310\lib\site-packages\mangadex\errors.py", line 15, in __init__ self.details = self.resp.text["detail"] TypeError: string indices must be integers
When i am just doing this:
chapter_list = getMangaChapters( api.get_manga_volumes_and_chapters(manga_id="248525ed-ad1c-4ddc-a834-5d6ce66a3ad2",translatedLanguage='en'))
It justs happens with the fetchimage method again, yesterday was just fine and now
The implementation seems fine, I just need to test it and give you an example of how to implement it directly onto the class (or if you prefer, I can do it and credit you on a comment).
For the second part, the thing is that you are exceeding the rate limits on the queries to the server https://api.mangadex.org/docs.html#section/Rate-limits you can only do 40 per minute, there you can set a timer or just fetch them as you need to.
Okay, and what is it mean that links are valid for 15 min in the fetchimage method? does it mean that after that time the links are useless?
No, the links are valid forever (unless the image server is down), the only thing that is valid for 15 minutes, is the session header when you log in
So it is normal to still having the same issue after 2 hours? Is there an alternative to the method fetchchapterimages?
So i have a problem with the fetchchapterimages method that throws me a typeerror exception:
I dont know if i am doing something not correctly or something, thanks in advance PD: I am new as python developer