Python:为什么我从cron调用时会从Babel获得此异常?

当我的脚本调用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'
UPDATE 当从命令行调用时,locale是en_US,当从cron None调用时。从cron调用它时如何设置它? 此外,不知道这是否重要,但调用Babel的脚本是自定义的django-admin命令。     
已邀请:
Babel无法检测到默认语言环境(对于LC_TIME),因为cron设置的环境变量较少。 你可以明确地设置这个
babel.dates.LC_TIME = Locale.parse('en_US')
。另请查看Babel 0.9.6 - 我们在默认的区域设置检测中有一些修复。     

要回复问题请先登录注册