Confuzu / CivitAI-Model-grabber

The Script Downloads in bulk both model(Lora,Lycoris,Embeding etc..) and related images, from a given CivitAI Username
GNU General Public License v3.0
18 stars 4 forks source link

Suggestion/Code_Improvement__Avoiding : UnicodeEncodeError_'charmap' codec can't encode characters in position ... #11

Closed ElRandom78 closed 2 months ago

ElRandom78 commented 2 months ago

Hi Confuzu, Thank you, for 0.3 Bugfix and for the costant improvement of code's Error Handling.

If I may, I'd like to suggest a little change at the code to further increase error handling (I analized and changed the lines through Pycharm and tested the code šŸ‘ ; as OS , I use Windows 10 on my PC)

changed line 182 of the code (and some others) as below:

with open(failed_downloads_file, "a", encoding='utf-8') as f:

(I simply added the argument: encoding='utf-8' at the function)

I made this change to bypass UnicodeEncodeError shown as below in the log:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "C:\Users\Francesco\AppData\Local\Programs\Python\Python310\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 152-157: character maps to <undefined>

I attach the code modified in the .ZIP.

civitAI_Model_downloader.zip

Hope this can help all you guys for a smoother download...šŸ‘

Confuzu commented 2 months ago

i added the utf-8 encoding