我遇到了一個很難追查的錯誤,所以我想我會在這裏添加原因+「解決方案」。AppEngine:開始任務時發生的gaierror
設置: Devbox - 運行Google App Engine監聽所有啓動任務的URL的端口(「--address = 0.0.0.0」)。 客戶端 - 客戶端(Python的請求庫)的查詢回調URL
應用程序引擎代碼:
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正在使用請求的'host'字段來爲該任務構建絕對URL。在/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/taskqueue/taskqueue_stub.py(1829):
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)
在我的情況下,我在遠程客戶端上使用特殊名稱+主機文件來訪問服務器。 192.168.1.208 devbox 因此,遠程客戶端的「主機」看起來像本地服務器無法解析的「devbox:8085」。
我真的不清楚你在這裏做什麼。什麼是「遠程客戶端」,它在做什麼?我假設你正在從其他機器獲取排隊任務的URL,但是這與任務重試有什麼關係呢? – 2012-03-24 09:52:57
是的,這是一個簡單的應用程序,在獲取某個URL時啓動任務,並且試圖在我的本地開發環境(在Macbook上運行的GoogleAppEngineLauncher)中對其進行測試。這裏的技巧是,獲取URL的客戶機是另一臺機器(具有不同的IP地址),而不是通過dev_appserver通常綁定的環回的瀏覽器。 – 2012-03-26 22:42:31
該任務失敗,因爲AppEngine在其HTTP請求中使用客戶端提供的主機名來爲任務生成絕對URL。如果客戶端使用在其hosts文件中定義的名稱,那麼當服務器無法解析名稱時,將無法在服務器上創建該任務。 – 2012-03-26 22:45:54