python - 使用 Python API 时出现 Google App Engine 任务队列错误

标签 python google-app-engine task-queue flask

我已经为 Flask + GAE 项目实现了一个任务队列操作,我正在使用它来了解有关 Python Web 开发的更多信息,但我收到以下错误,并且无法追踪有关它的任何信息。

----------------------------------------
Exception happened during processing of request from ('0.1.0.2', 80)
Traceback (most recent call last):
 File "/usr/local/Cellar/python/2.7.1/lib/python2.7/SocketServer.py", line 284, in    _handle_request_noblock
self.process_request(request, client_address)
File "/usr/local/Cellar/python/2.7.1/lib/python2.7/SocketServer.py", line 311, in process_request
self.shutdown_request(request)
File "/usr/local/Cellar/python/2.7.1/lib/python2.7/SocketServer.py", line 459, in    shutdown_request
request.shutdown(socket.SHUT_WR)
AttributeError: 'FakeConnection' object has no attribute 'shutdown'
----------------------------------------

我有一个 View 正在接受来自应用程序中另一个 View 的 POST 请求,据我所知,它正在执行我期望的所有处理,除了它到达末尾并将其吐出之外。我之所以这么猜测是因为我在 GAE devserver 日志中看到了以下输出:

INFO     2011-01-23 21:41:16,865 dev_appserver.py:3317] "GET /main/new HTTP/1.1" 200 -
INFO     2011-01-23 21:41:23,753 dev_appserver.py:3317] "POST /main/new HTTP/1.1" 302 -
INFO     2011-01-23 21:41:24,528 dev_appserver.py:3317] "POST /tasks/check_for_spam HTTP/1.1" 200 -

check_for_spam 是一个通过 Defensio API 运行一些数据来确定是否是垃圾邮件的函数。这是代码

from google.appengine.api import taskqueue
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

from application.models import LieModel
from defensio import *

class SpamChecker(webapp.RequestHandler):
    def post(self):
        id = self.request.get('id')
        client = Defensio('577709b41d42f2c34f80cd57d50333d6') 
        q = LieModel.all()
        q.filter("id = ", id)
        results = q.fetch(1)

        for result in results:
            title_doc = {'content': result.title, 'type': 'comment', 'platform':'python'}
            body_doc = {'content': result.body, 'type': 'comment', 'platform':'python'}
            title_status,title_response = client.post_document(title_doc)
            body_status,body_response = client.post_document(body_doc)
            lie_is_spam = False

            if title_status == 200 and title_response['defensio-result']['spaminess'] > 0.5:
                lie_is_spam = True

            if body_status == 200 and body_response['defensio-result']['spaminess'] > 0.5:
                lie_is_spam = True

            if lie_is_spam:
                lie_k = db.Key.from_path('Lie', id)
                lie = db.get(lie_k)
                lie.delete()


def main():
    run_wsgi_app(webapp.WSGIApplication([
        ('/tasks/check_for_spam', SpamChecker)
        ]))

if __name__ == '__main__':
    main()

任何有关解决此问题的帮助将不胜感激。

最佳答案

根据 Robert Kluin 的建议,问题就消失了。我正在使用启动开发服务器

python2.5 /usr/local/bin/dev_appserver.py .

关于python - 使用 Python API 时出现 Google App Engine 任务队列错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4777046/

相关文章:

java - 将图像解压缩到 blobstore

python - 在 Django 中使用 Google App Engine 队列服务

python - GAE 中的 TaskTooLargeError 是什么?

python - 任务队列停止工作

python - 异步运行一些 Python 代码的正确方法是什么?

python - Pandas 数据框中的非统一日期列

python - GAE 将字典转换为 NDB 数据存储实体

python - 类型错误 : unsupported operand type(s) for -: 'str' and 'datetime.datetime'

python - 在python中裁剪图像

java - 部署到应用程序引擎时出现 400 错误请求