【问题标题】:GAE Python AssertionError: write() argument must be stringGAE Python AssertionError: write() 参数必须是字符串
【发布时间】:2013-09-15 16:25:47
【问题描述】:

我正在使用 Sublime Text 2 作为我的编辑器并创建一个新的 Google App Engine 项目。

编辑:我正在通过 localhost 运行此代码。在 apppot 上查看应用程序时出现此错误: Status: 500 Internal Server Error Content-Type: text/plain Content-Length: 59 A server error occurred. Please contact the administrator.

我有这个代码:

import webapp2 as webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class IndexPage(webapp.RequestHandler):
    def get(self):
        self.response.out.write('Hello, World!')

app = webapp.WSGIApplication([('/.*', IndexPage)], debug = True)

def main():
    run_wsgi_app(app)

if __name__ == '__main__':
    main()

它会导致 AssertionError:

文件“C:\Python27\lib\wsgiref\handlers.py”,第 202 行,写入

assert type(data) is StringType,"write() argument must be string"

AssertionError: write() 参数必须是字符串

错误是什么意思,是什么原因造成的?

【问题讨论】:

  • 您使用的是 python 2.7 运行时吗? run_wsgi_app() 通常不再使用。
  • @Wooble 是的,我使用的是 python 2.7; run_wsgi_app() 是我通常使用的。正确的方法是什么?
  • 您通常只需设置app 变量并设置app.yaml 以将其用作WSGI 应用程序。
  • @Wooble 如果我将代码的结尾更改为:app = webapp.WSGIApplication([('/', IndexPage)], debug = True) 并添加到 YAML:- url: /.* script: index.app 它仍然给出相同的错误
  • stackoverflow.com/questions/8558323/… 看起来像一个类似的问题,除了在您的情况下您提供的是字符串文字,而不是呈现为 unicode 的模板,因此错误消息在这里没有意义。

标签: html google-app-engine python-2.7


【解决方案1】:

GAE 无法正确识别我的 app.yaml 文件。一旦我解决了这个问题,它就起作用了。谢谢

【讨论】:

    猜你喜欢
    • 2017-04-23
    • 2021-02-02
    • 2019-05-14
    • 2018-04-12
    • 1970-01-01
    • 2015-09-25
    • 2020-05-05
    • 2017-05-06
    • 2019-11-04
    相关资源
    最近更新 更多