【问题标题】:How to modify blobstoreuploadhandler to admit status 200?如何修改 blobstoreuploadhandler 以承认状态 200?
【发布时间】:2011-08-27 20:02:40
【问题描述】:

据说 GAE SDK 1.5.4 已经删除了 blobstoreuploadhandler 必须返回重定向的要求,并且在生产中它应该已经被认为已经如此,以便处理程序可以对带有模板变量的模板进行“常规”响应。我需要 dev_appserver 的这种功能,因此询问我如何修改 dev_appserver 以允许处理程序使用模板变量呈现模板。我想我需要更改的代码在文件中 http://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/tools/dev_appserver_blobstore.py 但我不确定要修改什么。你能告诉我如何使处理程序能够定期响应吗?

  def EndRedirect(self, redirected_outfile, original_outfile):
      """Handle the end of upload complete notification.

      Makes sure the application upload handler returned an appropriate status
      code.
      """
      response = dev_appserver.RewriteResponse(redirected_outfile)
      logging.info('Upload handler returned %d', response.status_code)

      if (response.status_code in (301, 302, 303) and
          (not response.body or len(response.body.read()) == 0)):
        contentless_outfile = cStringIO.StringIO()


        contentless_outfile.write('Status: %s\n' % response.status_code)
        contentless_outfile.write(''.join(response.headers.headers))
        contentless_outfile.seek(0)
        dev_appserver.URLDispatcher.EndRedirect(self,
                                                contentless_outfile,
                                                original_outfile)
      else:
        logging.error(
            'Invalid upload handler response. Only 301, 302 and 303 '
            'statuses are permitted and it may not have a content body.')
        original_outfile.write('Status: 500\n\n')

更新:解决方案已发布在此链接https://groups.google.com/forum/#!topic/google-appengine-python/vnvhUG1-UN0

【问题讨论】:

  • 你不能等待 1.5.4,或者同时在生产中测试吗?
  • 您是否尝试将 200 添加到列表中 (301, 302, 303)
  • 感谢您的回复。是的,我可以等。是的,我尝试将 200 添加到列表中,但没有这样做,所以也许这不是微不足道的,而是更好地处理我自己的代码,只保留我想要升级的方法的 2 个版本(这是一个混乱的类,我我在 codereview.stack 获得帮助...)我可以等待 1.5.4 或在生产中测试。
  • 请将解决方案作为答案发布,并接受它。

标签: python google-app-engine blobstore


【解决方案1】:

解决方案已发布,我可以验证它是否有效:

def EndRedirect(self, dispatched_output, original_output):

"""Handle the end of upload complete notification. Makes sure the application upload handler returned an appropriate status code. """

    response = dev_appserver.RewriteResponse(dispatched_output)

    logging.info('Upload handler returned %d', response.status_code)
    outfile = cStringIO.StringIO()
    outfile.write('Status: %s\n' % response.status_code)

    if response.body and len(response.body.read()) > 0:
      response.body.seek(0)
      outfile.write(response.body.read())
    else:
      outfile.write(''.join(response.headers.headers))

    outfile.seek(0)

dev_appserver.URLDispatcher.EndRedirect(self,outfile,original_output)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多