App Engine 在部署时出现数字格式错误
我刚刚部署了我的应用程序,一旦进入主页,我就会看到“500 内部服务器错误”页面。查看日志后,我收到以下错误:
type 'exceptions.SyntaxError'>: 文件 /base/data/home/apps/spare-wheels/1.348259065130939449/sparewheels.py 中第 465 行出现非 ASCII 字符 '\xc2',但未声明编码;请参阅http://www.python.org/peps/pep-0263.html 详细信息(sparewheels.py,第 465 行)
问题的行如下所示:
self.template_values['price_pounds'] = "£%.2f" % (float(self.event.price_pence)/100)
在本地主机上运行时效果很好:是否存在 Google Apps 版本的 Python 不支持的数字格式?
I have just deployed my app and as soon as I go on the homepage I get the '500 internal server error' page. Having looked through the logs I got the following error:
type 'exceptions.SyntaxError'>: Non-ASCII character '\xc2' in file /base/data/home/apps/spare-wheels/1.348259065130939449/sparewheels.py on line 465, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details (sparewheels.py, line 465)
The line in question looks like this:
self.template_values['price_pounds'] = "£%.2f" % (float(self.event.price_pence)/100)
This worked fine when running on localhost: is there something about number formatting that the Google Apps version of Python doesn't support?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查python文件的编码,是UTF-8吗?该错误消息表明您可能已将文件保存为 ASCII 格式,文件中包含国际字符(又名“£”),导致 Google 的 python 运行时抛出 500 错误。
还可以尝试将此行放在 python 文件的第一行或第二行上:
Check the encoding of the python file, is it UTF-8? That error message suggests you may have saved the file as an ASCII format with international characters in the file (aka "£") causing Google's python runtime to barf up that 500 error.
Also try tossing this line on the first or second line of the python file:
如果您不想像 @Shakakai 建议的那样破坏文件编码,并且这是您在源代码中处理的唯一非 ASCII 字符,您也可以将该字符替换为等效的 HTML 实体
& pound;
,它将正确渲染。If you don't want to muck with file encodings as @Shakakai suggests, and that's the only non-ASCII character you're dealing with in your source, you could also just replace that character with the equivalent HTML entity
£
, which will render out correctly.