我遇到了一个很难跟踪的错误,所以我想我会在这里添加原因+“解决方案”。
设置: Devbox - 在所有端口上运行Google App Engine(“--address = 0.0.0.0”),提供启动任务的URL。 客户端 - 查询回调URL的客户端(Python请求库)
App Engine代码:
class StartTaskCallback(webapp.RequestHandler):
def post(self):
param = self.request.get('param')
logging.info('STARTTASK: %s' % param)
# launch a task
taskqueue.add(url='/tasks/mytask',
queue_name='myqueue',
params={'param': param})
class MyTask(webapp.RequestHandler):
def post(self):
param = self.request.get('param')
logging.info('MYTASK: param = %s' % param)
当我用浏览器查询回调时,一切正常,但来自远程客户端的相同查询给了我以下错误:
ERROR 2012-03-23 21:18:27,351 taskqueue_stub.py:1858] An error occured while sending the task "task1" (Url: "/tasks/mytask") in queue "myqueue". Treating as a task error.
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/taskqueue/taskqueue_stub.py", line 1846, in ExecuteTask
connection.endheaders()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/httplib.py", line 868, in endheaders
self._send_output()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/httplib.py", line 740, in _send_output
self.send(msg)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/httplib.py", line 699, in send
self.connect()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/httplib.py", line 683, in connect
self.timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/socket.py", line 498, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
gaierror: [Errno 8] nodename nor servname provided, or not known
当任务重试时,此错误只会在循环中旋转。奇怪的是,我可以去管理员 - >任务队列并单击“运行”以使任务成功完成。
起初我以为这是绑定错误。如果我通过浏览器查询StartTaskCallback或者我在本地运行客户端,我不会收到错误。
最后,我注意到App Engine正在使用请求的“主机”字段,以便为任务构建绝对URL。在/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/taskqueue/taskqueue_stub.py(1829):[/ p>
connection_host, = header_dict.get('host', [self._default_host])
if connection_host is None:
logging.error('Could not determine where to send the task "%s" '
'(Url: "%s") in queue "%s". Treating as an error.',
task.task_name(), task.url(), queue.queue_name)
return False
connection = httplib.HTTPConnection(connection_host)
就我而言,我在远程客户端上使用特殊名称+ hosts文件来访问服务器。 192.168.1.208 devbox 因此,远程客户端的“主机”看起来像“devbox:8085”,本地服务器无法解析。
答案 0 :(得分:2)
为了解决这个问题,我只是将devbox添加到我的AppEngine服务器的hosts文件中,但是如果gaierror异常打印出无法解析的名称,或者App Engine没有使用'主机',那肯定会很好'为构建任务创建URL的传入请求。