huyndao / apod-download

apod-dl.py: Download pictures from NASA's APOD (Astronomy Picture of the Day) site
MIT License
4 stars 1 forks source link

Error when encoding 'ş' character #1

Open Mr6686 opened 1 year ago

Mr6686 commented 1 year ago

When parsing https://apod.nasa.gov/apod/ap230102.html, the script throw a error when encoding the unicode character 'ş'.

The error displayed:

getting image from https://apod.nasa.gov/apod/ap230102.html save album list to apod-images\album_list.txt Traceback (most recent call last): File "E:\py\apod-dl.py", line 136, in url = get_apod(url, SAVEDIR) File "E:\py\apod-dl.py", line 48, in get_apod albumfd.write( File "C:\Users\Michael\AppData\Local\Programs\Python\Python311\Lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u015f' in position 821: character maps to <undefined>

Mr6686 commented 1 year ago

I managed to fix the error by adding , encoding='utf-8' line 46: with open(os.path.join(adir, "album_list.txt"), "at", encoding='utf-8') as albumfd: