Pelican: macosx python 3 and 2.7: ValueError: unknown locale: UTF-8

Created on 23 Feb 2018  路  7Comments  路  Source: getpelican/pelican

Hi!
Tried both Python 3 and Python 2 with same result:

Traceback (most recent call last):
  File "/Users/manel/devel/opensource/pygrn/scms/venv/bin/pelican-quickstart", line 7, in <module>
    from pelican.tools.pelican_quickstart import main
  File "/Users/manel/devel/opensource/pygrn/scms/venv/lib/python2.7/site-packages/pelican/tools/pelican_quickstart.py", line 25, in <module>
    _DEFAULT_LANGUAGE = locale.getlocale()[0]
  File "/Users/manel/devel/opensource/pygrn/scms/venv/lib/python2.7/locale.py", line 562, in getlocale
    return _parse_localename(localename)
  File "/Users/manel/devel/opensource/pygrn/scms/venv/lib/python2.7/locale.py", line 475, in _parse_localename
    raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

All 7 comments

A good way to troubleshoot errors is to try using the error as a search term across the Internet:

http://www.lmgtfy.com/?q=ValueError%3A+unknown+locale%3A+UTF-8

By doing that, you'll almost always find someone else who has run into the same problem, along with a solution. If you need further assistance, please consider reaching out via the Pelican IRC channel, as noted in the How to Get Help section of the documentation. Thanks!

@justinmayer thanks! Sure thing, that is what I always do. I thought I'd report it as a bug since it can be easily intercepted, and if not fix it, point the user to the solution.

I agree that would be helpful. Is that something you'd be willing to help improve? If so, I'd be happy to re-open the issue.

What about this, it works for me (same as you do for _DEFAULT_TIMEZONE):

locale.setlocale(locale.LC_ALL, '')
try:
    _DEFAULT_LANGUAGE = locale.getlocale()[0]
except Exception:
    _DEFAULT_LANGUAGE = None
if _DEFAULT_LANGUAGE is None:
    _DEFAULT_LANGUAGE = 'English'
else:
    _DEFAULT_LANGUAGE = _DEFAULT_LANGUAGE.split('_')[0]

Let's ask our resident locale expert, @avaris... What do you think?

Effectively this is an issue with Python and OSX. But it's fine to circumvent it, I guess. It doesn't seem to be going away soon.

As for the patch, just catch the exact exception please (ValueError). except Exception is far too broad. Plus, maybe a comment why that's needed.

Done. I used ValueError initially, but then I thought that any exception while autodetecting the language is not as important as keeping the quickstart process going. The PR only catches ValueError though.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Kristinita picture Kristinita  路  8Comments

mandaris picture mandaris  路  4Comments

quack1 picture quack1  路  6Comments

georgiastuart picture georgiastuart  路  7Comments

begueradj picture begueradj  路  7Comments