Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when downloading episodes with UTF-8 characters in their names #12

Closed
psy-q opened this issue Jun 5, 2016 · 4 comments
Closed

Comments

@psy-q
Copy link

psy-q commented Jun 5, 2016

At least I think that's the problem:

DiskStation$ python autoTatort.py 
Traceback (most recent call last):
  File "autoTatort.py", line 218, in <module>
    if (os.path.isfile(fullFileName)) == True:
  File "/usr/local/lib/python2.7/genericpath.py", line 29, in isfile
    st = os.stat(path)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xc4' in position 45: ordinal not in range(128)
@dicer
Copy link
Owner

dicer commented Aug 5, 2016

I really hate python for string handling...

If this happens again, please try swapping line 217 to this:
fullFileName = u"" + targetDir + fileName + ".mp4"

Or if you know your way around python, try adding a u in front of strings. Kinda like this old commit which never made it in cause it doesn't happen to me: d47be7c

@psy-q
Copy link
Author

psy-q commented Aug 18, 2016

Hmm. This was using a Python version compiled for PPC on a Synology NAS. I've now tried autoTatort on a RaspberryPi (mounting that NAS) and that seems to work fine. So it may be something about the Python version on the NAS and autoTatort is innocent.

@psy-q
Copy link
Author

psy-q commented Jun 24, 2017

I'm now having the issue again since I tried moving my autoTatort.py back to the NAS so it doesn't require an additional external device. I can reproduce it using a freshly installed Synology NAS with the latest Disk Station Manager (that's what Synology call their OS) and the official Python package by the Python Foundation from the package manager.

The line numbers have moved a little meanwhile:

Traceback (most recent call last):
  File "autoTatort.py", line 217, in <module>
    if (os.path.isfile(fullFileName)) == True:
  File "/usr/lib/python2.7/genericpath.py", line 37, in isfile
    st = os.stat(path)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 59: ordinal not in range(128)

Python is at 2.7.12. Would it be possible to perhaps specify an explicit codec so that the filename can be written, or to convert filenames with non-ASCII characters to ASCII? The filesystem itself can take UTF8 fine, it's ext4.

@psy-q
Copy link
Author

psy-q commented Jun 24, 2017

Solved it, I think. The "Task Scheduler" component of a Synology NAS does not inherit the locale that is set system-wide in the settings. I have to set the "User-defined script" part of the scheduled task configuration as follows:

LC_ALL=en_US.UTF-8 /bin/python autoTatort.py

This makes it work. Various documentation says that you should never set LC_ALL unless you're debugging something, but I don't know which of the locale env vars is responsible for the filesystem encoding or the codec that Python chooses, so I simply set LC_ALL.

dicer added a commit that referenced this issue Sep 22, 2017
@dicer dicer closed this as completed Sep 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants