【发布时间】:2012-10-24 14:44:52
【问题描述】:
我有一个 Google AppEngine 应用程序,它在我的本地机器上运行良好。该应用程序将图像(来自 url)发布到我的 facebook 墙上。但是,当我将它部署到 Google 的服务器时,我得到了 一个错误:
DeadlineExceededError: Deadline exceeded while waiting for HTTP response from URL:
违规代码是:
facebook_access_token = facebook_info['access_token']
facebook_post_url = 'https://graph.facebook.com/me/photos?access_token=%s&url=%s&name=%s&method=post' % (facebook_access_token, url, caption)
facebook_post_url = facebook_post_url.replace(" ", "+");
facebook_result = urlfetch.fetch(facebook_post_url)
if facebook_result.status_code == 200:
facebook_result_object = json.loads(facebook_result.content)
output_ids['facebook'] = facebook_result_object['id']
else:
output_ids['facebook'] = ''
完整的错误跟踪是:
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py", line 710, in __call__
handler.get(*groups)
File "/base/data/home/apps/s~digibackapi/1.362663258877230387/main.py", line 512, in get
facebook_result = urlfetch.fetch(facebook_post_url)
File "/base/python_runtime/python_lib/versions/1/google/appengine/api/urlfetch.py", line 266, in fetch
return rpc.get_result()
File "/base/python_runtime/python_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 604, in get_result
return self.__get_result_hook(self)
File "/base/python_runtime/python_lib/versions/1/google/appengine/api/urlfetch.py", line 404, in _get_fetch_result
'Deadline exceeded while waiting for HTTP response from URL: ' + url)
DeadlineExceededError: Deadline exceeded while waiting for HTTP response from URL: https://graph.facebook.com/me/photos?access_token=<ACCESS_TOKEN>&url=http://digiback.cc/ej7&name=Trees&method=post
再一次,代码对我来说看起来很可靠,并且在我的本地机器上运行正常。它与超时有什么关系吗?当我在浏览器中尝试facebook_post_url 时,它会立即返回。
有人有什么想法吗?我在这里完全迷失了。
非常感谢!
【问题讨论】:
-
在黑暗中拍摄,但您是否尝试过使用其他图像?由于您的 URL 看起来构造正确,我想知道这是否与您作为
url参数包含的图像有关。这是完全没有根据的,但我很好奇缩短的 URL 是如何被解析的,以及使用直接 URL 是否可行(至少作为测试)。此外,您可以使用urllib.urlencode来构建 URL,但是一旦我们解决了这个问题,我们就可以使用它了 :) -
不幸的是,在硬编码的完整 url 中进行替换没有帮助:-/ 我意识到 DDE 错误是一个通用的 urlfetch 错误,从描述来看,好像 urlfetch 请求花费的时间太长。但是为什么在浏览器中调用几乎是即时的,并且在我的本地 appengine 环境中运行时?
-
您是否正确设置了developers.facebook.com 中的site_url/domain(我假设它是127.0.0.1 用于本地测试)?还要调整 urlfetch 截止日期。 developers.google.com/appengine/docs/python/urlfetch/…(默认为 5 秒)
-
@Bert 看起来增加了截止日期。我猜 Facebook 图片帖子(即使来自 url)只需要 5 秒以上。谢谢你的帮助!如果您想将此作为正式答案发布,我会接受。
-
@Brett 太棒了!我通常也会将我的 facebook 调用置于延迟任务中,以防它们需要很长时间(不确定你是否已经这样做了)。
标签: python google-app-engine urlfetch