OwenTruong / civitdl

A CLI python script to batch download models from CivitAI with CivitAI Api V1
Apache License 2.0
42 stars 5 forks source link

401 errors for some models? #90

Closed cliffrowley closed 5 months ago

cliffrowley commented 5 months ago

I'm not sure why but some models refuse to download (even with an API key) and return a 401 error, despite being able to download them manually from the website directly.

For example:

---------

APIException (API Status Code 401):
         Downloading model from CivitAI failed for model id, 282171, and version id, 317633

---------
Retrying to download the current model...
Now downloading "Yellow summer dress"...
            - Model ID: 282171
            - Version ID: 317633

---------

I've tried waiting and retrying, even waiting a whole day just in case it's one of their weird proxy errors, but nada.

OwenTruong commented 5 months ago

Strange, when I use wget it is able to fetch the model.... I will try to investigate more about this.

wget https://civitai.com/api/download/models/317633?token={api_key} --content-disposition

Edit:

This python code gives back status 200 too.. strange ` session = requests.session() res = session.get( f"https://civitai.com/api/download/models/317633", stream=True, headers=headers)

print(res.status_code) `

OwenTruong commented 5 months ago

Ok I managed to figure out the reason why. It was because the program didn't expect CivitAI to send a 401 error for unauthorized models. The program expected CivitAI to redirect to a url with "reason=download-auth" in the url. This bug will be fixed in version 2.0.12 in a sec.

First time finding out that CivitAI is capable of throwing 401 errors lol

cliffrowley commented 5 months ago

Wonderful, thanks!