当我的脚本调用 Babel 函数时,我从 Python Babel 包中抛出了这个异常。问题是当我从命令行运行它时它工作正常。但是,这是我从 cron 运行它时遇到的错误。似乎它可能与某些环境或语言环境设置或缺少它有关。
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'
更新
从命令行调用时,语言环境是 en_US,从 cron None 调用时。从cron调用它时如何设置它?
另外,不知道这是否重要,但调用 Babel 的脚本是自定义的 django-admin 命令。