简体   繁体   English

Google Appengine和Python例外

[英]Google Appengine and Python exceptions

In my Google Appengine application I have defined a custom exception InvalidUrlException(Exception) in the module 'gvu'. 在我的Google Appengine应用程序中,我已在模块“ gvu”中定义了一个自定义异常InvalidUrlException(Exception)。 Somewhere in my code I do: 在我的代码中的某个地方,我这样做:

try:
    results = gvu.article_parser.parse(source_url)
except gvu.InvalidUrlException as e:
    self.redirect('/home?message='+str(e))
...

which works fine in the local GAE development server, but raises 在本地GAE开发服务器上可以正常运行,但会提高

<type 'exceptions.SyntaxError'>: invalid syntax (translator.py, line 18)

when I upload it. 当我上传它时。 (line 18 is the line starting with 'except') (第18行是以“ except”开头的行)

The problem seems to come from the 'as e' part: if I remove it I don't get this exception anymore. 问题似乎出在“ as e”部分:如果我将其删除,则不会再出现此异常。 However I would like to be able to access the raised exception. 但是,我希望能够访问引发的异常。 Have you ever encountered this issue? 您是否遇到过此问题? Is there an alternative syntax? 有替代语法吗?

You probably have an older Python version on your server. 您的服务器上可能装有较旧的Python版本。 except ExceptionType as varname: is a newer syntax. except ExceptionType as varname:是一种较新的语法。 Previously you needed to simply use a comma: except ExceptionType, varname: . 以前,您只需要简单地使用逗号: except ExceptionType, varname:

我遇到了同样的错误,因为我在使用python3打印语句(带括号的打印语句)的python3文件上使用pydoc命令而不是pydoc3命令。

Just FYI, another possible cause for this error - especially if the line referenced is early in the script (like line 2) is line ending differences between Unix and Windows. 仅供参考,导致此错误的另一个可能原因-尤其是如果所引用的行在脚本的早期(如第2行)是Unix和Windows之间的行尾差异。

I was running Python on Windows from a Cygwin shell and got this error, and was really puzzled. 我从Cygwin外壳在Windows上运行Python,却遇到此错误,这真让我感到困惑。 I had created the file with "touch" before editing it. 在编辑文件之前,我已经通过“触摸”创建了文件。

I renamed the file to a temp file name, and copied another file (which I had downloaded from a Unix server) onto the original file name, then restored the contents via the temp file, and problem solved. 我将文件重命名为临时文件名,然后将另一个文件(我从Unix服务器下载的文件)复制到原始文件名,然后通过临时文件恢复了内容,并解决了问题。 Same exact file contents (on the screen anyway), only difference was where the file had originally been created. 完全相同的文件内容(无论如何在屏幕上),唯一的区别是文件最初创建的位置。

Just wanted to post this in case anyone else ran across this error and was similarly puzzled. 只是想发布此内容,以防其他人遇到此错误并同样感到困惑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM