Bre*_*ett 17 python google-app-engine urlfetch
我有一个Google AppEngine应用程序,它在我的本地计算机上运行良好.该应用程序将图像(从网址)发布到我的Facebook墙上.但是,当我将其部署到Google的服务器时,我收到一个错误:
DeadlineExceededError: Deadline exceeded while waiting for HTTP response from URL:
Run Code Online (Sandbox Code Playgroud)
违规代码是:
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'] = ''
Run Code Online (Sandbox Code Playgroud)
Ans完整的错误跟踪是:
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
Run Code Online (Sandbox Code Playgroud)
同样,代码对我来说看起来很可靠,并且在我的本地机器上运行正常.这可能与超时有关吗?当我facebook_post_url在浏览器中尝试时,它会立即返回.
有没有人有任何想法?我在这里完全失败了.
非常感谢!
Ran*_*ku' 28
简单回答:网址提取的默认截止日期设置为5秒.
怎么修:
from google.appengine.api import urlfetch
urlfetch.set_default_fetch_deadline(60)
Run Code Online (Sandbox Code Playgroud)
尝试将urlfetch的截止日期设置为30秒或更长时间(取决于您是否在任务处理程序或请求处理程序中调用urlfetch)
有关urlfetch的更多信息:Url Fetch Docs
| 归档时间: |
|
| 查看次数: |
11156 次 |
| 最近记录: |