L4cache / kemono-dl

(personal fork of) A simple kemono.party downloader using python.
93 stars 14 forks source link

TypeError: 'str' object does not support item assignment #20

Closed shodanwang closed 10 months ago

shodanwang commented 10 months ago

Version

Version: 2022.04.28 ( b332e0ab799eafcea9b2970cee85ce70507db87b ) Version string seems not updated. The commit hash is the latest in this repo.

Your Command

# The kemono.party post link is ommitted. Any link will trigger the error.
python3 ~/kemono-dl/kemono-dl.py --cookies "./kemono.party_cookies.txt" --links <a kemono.party post link> --dirname-pattern "./{username}" --filename-pattern "{title}/{id}_{index}.{ext}" --verbose

Description of bug

It will fail to download the post and show the following error message:

2023-10-20 12:17:21,121:DEBUG:Getting creator json from https://kemono.party/api/v1/creators/
2023-10-20 12:17:23,365:INFO:Downloading posts from kemono.party.party | fanbox | <ommitted> | <ommitted>
2023-10-20 12:17:23,365:DEBUG:Requesting post json from: https://kemono.party/api/v1/fanbox/user/<ommitted>/post/<ommitted>
2023-10-20 12:17:23,631:ERROR:Unable to get posts for https://kemono.party/fanbox/user/<ommitted>/post/<ommitted>
Traceback (most recent call last):
  File "~/kemono-dl/src/main.py", line 826, in start_download
    self.get_post(url)
  File "~/kemono-dl/src/main.py", line 189, in get_post
    post['site']=site
TypeError: 'str' object does not support item assignment

How To Reproduce

Run the above command with any kemono.party post link.

Error messages and tracebacks

2023-10-20 12:17:21,121:DEBUG:Getting creator json from https://kemono.party/api/v1/creators/
2023-10-20 12:17:23,365:INFO:Downloading posts from kemono.party.party | fanbox | <ommitted> | <ommitted>
2023-10-20 12:17:23,365:DEBUG:Requesting post json from: https://kemono.party/api/v1/fanbox/user/<ommitted>/post/<ommitted>
2023-10-20 12:17:23,631:ERROR:Unable to get posts for https://kemono.party/fanbox/user/<ommitted>/post/<ommitted>
Traceback (most recent call last):
  File "~/kemono-dl/src/main.py", line 826, in start_download
    self.get_post(url)
  File "~/kemono-dl/src/main.py", line 189, in get_post
    post['site']=site
TypeError: 'str' object does not support item assignment

Additional comments

Any idea how to fix the issue ?

L4cache commented 10 months ago

The most likely reason is the 'json' here https://github.com/L4cache/kemono-dl/blob/e329ef093d75706b49384f21f7ebd49451b6507f/src/main.py#L180 is expected to be a list that contains dict(s) of each post content, but if input link is post link, it produces dict only, without the list 'shell' outside. This could be a changed behavior, because I don't remember encountered this problem. Turning it into a list with single member 'fixes' the problem, I don't know if it is too crude, please comment.

reasonabledoubt commented 10 months ago

Not the original issue reporter, but having the same problem, hoping these error reports can help:

Prior to this change, using b332e0ab799eafcea9b2970cee85ce70507db87b, error:

ERROR:Unable to get posts for https://coomer.party/onlyfans/user/<redacted>
Traceback (most recent call last):
  File "~/kemono-dl/src/main.py", line 825, in start_download
    self.get_post(url)
  File "~/kemono-dl/src/main.py", line 188, in get_post
    post['site']=site
TypeError: 'str' object does not support item assignment

After this change, using e329ef093d75706b49384f21f7ebd49451b6507f, different error:

ERROR:Unable to get posts for https://coomer.party/onlyfans/user/<redacted>
Traceback (most recent call last):
  File "~/kemono-dl/src/main.py", line 827, in start_download
    self.get_post(url)
  File "~/kemono-dl/src/main.py", line 192, in get_post
    if self.skip_post(post,True):
  File "~/kemono-dl/src/main.py", line 658, in skip_post
    if "https://{site}/{service}/user/{user}/post/{id}".format(**post) in self.archive_list:
KeyError: 'service'
L4cache commented 10 months ago

Not the original issue reporter, but having the same problem, hoping these error reports can help:

Prior to this change, using b332e0a, error:

ERROR:Unable to get posts for https://coomer.party/onlyfans/user/<redacted>
Traceback (most recent call last):
  File "~/kemono-dl/src/main.py", line 825, in start_download
    self.get_post(url)
  File "~/kemono-dl/src/main.py", line 188, in get_post
    post['site']=site
TypeError: 'str' object does not support item assignment

After this change, using e329ef0, different error:

ERROR:Unable to get posts for https://coomer.party/onlyfans/user/<redacted>
Traceback (most recent call last):
  File "~/kemono-dl/src/main.py", line 827, in start_download
    self.get_post(url)
  File "~/kemono-dl/src/main.py", line 192, in get_post
    if self.skip_post(post,True):
  File "~/kemono-dl/src/main.py", line 658, in skip_post
    if "https://{site}/{service}/user/{user}/post/{id}".format(**post) in self.archive_list:
KeyError: 'service'

Is the latter of mentioned errors happens when the download is near finished? This one is probably caused by the 'chunk_size' (offset factor) has been changed to 50 as well in coomer, like in kemono some time ago. Please check the latest change.

reasonabledoubt commented 10 months ago

Is the latter of mentioned errors happens when the download is near finished? This one is probably caused by the 'chunk_size' (offset factor) has been changed to 50 as well in coomer, like in kemono some time ago. Please check the latest change.

As I understand it, the errors were occurring before any download could occur (the parsing of the link/post, "unable to get posts" thus no download) so I don't think it could have been when anything was near finished.

However, now trying same after updating to 7d19bbeb5d42c2d619323c237d378caa375813fa seems to be working with no errors. Thanks!

@shodanwang you should try again too, see if this also fixes for you.

L4cache commented 10 months ago

As I understand it, the errors were occurring before any download could occur (the parsing of the link/post, "unable to get posts" thus no download) so I don't think it could have been when anything was near finished.

I said 'near finished' in the pseudo-for post in user context, not individual files.

If the total posts of the user is > 50, then it would fall under the len(json)==50 check, makes first few 'pages of posts' download flawlessly, the problem appears when the posts in the page is < 50 (which often happens in last 'page of posts', and is always the case if total posts of the user is < 50). Even then, the 'next page' request will only occur when 'current page' is finished, which actually contains complete last posts (or all posts if total posts < 50), if the request is successful it will only return overlapped result. (so it's even 'after finished' not 'near finish', probably)

At least that's my theory.

And I think the api behavior is changed as well, I remember it would actually return the aforementioned 'overlapped results' before, but it will return {"error":"offset not multiple of 50"} now. Overlapped results doesn't break the mechanism, they will be skipped immediately, but can cause excessive load on the server, return error breaks things but save server, I think it's better this way.

shodanwang commented 10 months ago

Can confirm that updating to 7d19bbe fixes the issue. Thank you @L4cache @reasonabledoubt for helping, I'll close the issue now.