locale.Error: unsupported locale setting?

Is your Python code crashing over some kind of locale setting?

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.6/dist-packages/tweepy/binder.py", line 178, in _call
    return method.execute()
  File "/usr/local/lib/python2.6/dist-packages/tweepy/binder.py", line 164, in execute
    result = self.api.parser.parse(self, resp.read())
  File "/usr/local/lib/python2.6/dist-packages/tweepy/parsers.py", line 72, in parse
    result = model.parse_list(method.api, json)
  File "/usr/local/lib/python2.6/dist-packages/tweepy/models.py", line 35, in parse_list
    results.append(cls.parse(api, obj))
  File "/usr/local/lib/python2.6/dist-packages/tweepy/models.py", line 50, in parse
    setattr(status, k, parse_datetime(v))
  File "/usr/local/lib/python2.6/dist-packages/tweepy/utils.py", line 20, in parse_datetime
    locale.setlocale(locale.LC_TIME, '')
  File "/usr/lib/python2.6/locale.py", line 513, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

Or when using aptitude or apt-get or dpkg-reconfigure, you also get some LANGUAGE or LC_ALL unset error?

jaysern@jaysern:/home/jaysern# dpkg-reconfigure localeconf
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
      LANGUAGE = (unset),
      LC_ALL = (unset),
      LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Package `localeconf' is not installed and no info is available.
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.

If you tried this in your python code,

locale.setlocale(locale.LC_ALL, '')

or

locale.setlocale(locale.LC_TIME, '')

does it fail too?

If so, try

aptitude install language-pack-en

and see if that does the trick for you (credit). I spent a few hours trying to hunt down a bug in python – turns out the solution was just a one-liner. I hope this saves someone else the headache!

Tags: ,

  • PowerPaul86

    thank you very much!

  • rolandixor

    I have installed but I'm going to reinstall and see if it works