I'm getting this exception thrown from within the Python Babel package when my script calls a Babel function. The thing is when I run it from the command line it works okay. However, this is the error I get when I run it from cron. It seems though it may be related to some environment or locale setting or lack of it.
File "/home/myproj/lib/python2.6/Babel-0.9.5-py2.6.egg/babel/dates.py", line 508, in format_datetime
return parse_pattern(format).apply(datetime, locale)
File "/home/myproj/lib/python2.6/Babel-0.9.5-py2.6.egg/babel/dates.py", line 702, in apply
return self % DateTimeFormat(datetime, locale)
File "/home/myproj/lib/python2.6/Babel-0.9.5-py2.6.egg/babel/dates.py", line 699, in __mod__
return self.format % other
File "/home/myproj/lib/python2.6/Babel-0.9.5-py2.6.egg/babel/dates.py", line 724, in __getitem__
return self.format_month(char, num)
File "/home/myproj/lib/python2.6/Babel-0.9.5-py2.6.egg/babel/dates.py", line 793, in format_month
return get_month_names(width, context, self.locale)[self.value.month]
开发者_如何转开发File "/home/myproj/lib/python2.6/Babel-0.9.5-py2.6.egg/babel/dates.py", line 87, in get_month_names
return Locale.parse(locale).months[context][width]
AttributeError: 'NoneType' object has no attribute 'months'
UPDATE
When called from the command line locale is en_US and when called from cron None. How do I set it when calling it from cron?
Also, don't know if this is important, but the script that calls into Babel is a custom django-admin command.
Babel was unable to detect a default locale (for LC_TIME) because cron sets fewer environment variables.
You could set this explicitely babel.dates.LC_TIME = Locale.parse('en_US')
. Also check out Babel 0.9.6 - there we some fixes in default locale detection.
精彩评论