Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何增加imaplib请求的超时?_Python_Google App Engine - Fatal编程技术网

Python 如何增加imaplib请求的超时?

Python 如何增加imaplib请求的超时?,python,google-app-engine,Python,Google App Engine,我正在使用imaplib查询Gmail的IMAP,但有些请求需要60秒以上才能返回。这已在任务中完成,因此我有整整10分钟的时间来执行请求,但由于urlfetch上的60秒限制,我的任务失败 我试过设置urlfetch.set\u default\u fetch\u deadline(600),但它似乎没有任何作用 这里有一个stacktrace: The API call remote_socket.Receive() took too long to respond and was canc

我正在使用
imaplib
查询Gmail的IMAP,但有些请求需要60秒以上才能返回。这已在任务中完成,因此我有整整10分钟的时间来执行请求,但由于
urlfetch
上的60秒限制,我的任务失败

我试过设置
urlfetch.set\u default\u fetch\u deadline(600)
,但它似乎没有任何作用

这里有一个stacktrace:

The API call remote_socket.Receive() took too long to respond and was cancelled.
Traceback (most recent call last):
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/imaplib.py", line 760, in uid
    typ, dat = self._simple_command(name, command, *args)
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/imaplib.py", line 1070, in _simple_command
    return self._command_complete(name, self._command(name, *args))
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/imaplib.py", line 897, in _command_complete
    typ, data = self._get_tagged_response(tag)
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/imaplib.py", line 999, in _get_tagged_response
    self._get_response()
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/imaplib.py", line 916, in _get_response
    resp = self._get_line()
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/imaplib.py", line 1009, in _get_line
    line = self.readline()
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/imaplib.py", line 1171, in readline
    return self.file.readline()
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/socket.py", line 445, in readline
    data = self._sock.recv(self._rbufsize)
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/ssl.py", line 301, in recv
    return self.read(buflen)
  File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/ssl.py", line 220, in read
    return self._sslobj.read(len)
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/remote_socket/_remote_socket.py", line 864, in recv
    return self.recvfrom(buffersize, flags)[0]
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/remote_socket/_remote_socket.py", line 903, in recvfrom
    apiproxy_stub_map.MakeSyncCall('remote_socket', 'Receive', request, reply)
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 94, in MakeSyncCall
    return stubmap.MakeSyncCall(service, call, request, response)
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 328, in MakeSyncCall
    rpc.CheckSuccess()
  File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/apiproxy_rpc.py", line 133, in CheckSuccess
    raise self.exception
DeadlineExceededError: The API call remote_socket.Receive() took too long to respond and was cancelled.

imaplib源代码中没有提到超时。因此,有几种选择:

  • 第二个选项是使用 可调超时,我们可以说在
  • 从表面上看,似乎有很多
    死线超出DederRor
    的可能原因

    在您的情况下,它可能是页面上显示的最后两种(三种类型中的一种)类型的
    deadlineexceedderror

    哪种类型的deadlineexceedderror? AppEngine中有三种类型的
    死线超出derror

  • google.appengine.runtime.DeadlineExceededError:如果整个请求超时,通常在60秒或10分钟后引发 用于任务队列请求
  • google.appengine.runtime.apiproxy_errors.deadlineExceederRor:如果RPC超过其截止日期,则引发。这通常是5秒, 但对于某些API,它可以使用“截止日期”选项进行设置
  • google.appengine.api.urlfetch_errors.DeadlineExceededError:如果urlfetch超时,则引发
  • 如你所见。
    taskqueue
    的10分钟限制只对
    google.appengine.runtime.DeadlineExceededError
    有帮助。
    死线超标错误的类型可以通过回溯(如下列表)进行识别。在本例中,它是
    google.appengine.runtime.apiproxy\u errors.DeadlineExceededError
    。默认情况下,它将在5秒内升高。(我会在弄清楚如何更改后更新帖子)

    类型1。google.appengine.runtime.deadlineExceederRor 回溯看起来像

    Traceback (most recent call last):
      File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 266, in Handle
        result = handler(dict(self._environ), self._StartResponse)
      File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__
        rv = self.router.dispatch(request, response)
      File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
        return route.handler_adapter(request, response)
      File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__
        return handler.dispatch()
      File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch
        return method(*args, **kwargs)
      File "/base/data/home/apps/s~tagtooadex2/test.371204033771063679/index.py", line 9, in get
        pass
    DeadlineExceededError
    
    DeadlineExceededError: Deadline exceeded while waiting for HTTP response from URL:     http://www.sogi.com.tw/newforum/article_list.aspx?topic_ID=6089521
    
    解决方案 使用taskqueue(10分钟)、后端或手动缩放选项可以解决此异常。

    类型2。google.appengine.runtime.apiproxy_errors.deadlineExceederRor 回溯看起来像

    DeadlineExceededError: The API call remote_socket.Receive() took too long to respond and was cancelled.
    
    类型3。google.appengine.api.urlfetch_errors.deadlineExceederRor 回溯看起来像

    Traceback (most recent call last):
      File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 266, in Handle
        result = handler(dict(self._environ), self._StartResponse)
      File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__
        rv = self.router.dispatch(request, response)
      File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
        return route.handler_adapter(request, response)
      File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__
        return handler.dispatch()
      File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch
        return method(*args, **kwargs)
      File "/base/data/home/apps/s~tagtooadex2/test.371204033771063679/index.py", line 9, in get
        pass
    DeadlineExceededError
    
    DeadlineExceededError: Deadline exceeded while waiting for HTTP response from URL:     http://www.sogi.com.tw/newforum/article_list.aspx?topic_ID=6089521
    
    解决方案: 这个例外可以通过延长截止日期来解决

    urlfetch.fetch(url, deadline=10*60)
    

    我不认为是套接字库超时了。(It)。似乎是阿彭尼把死线抛得太远了。所有请求限制为60秒。但由于我是在taskqueue中执行此操作,我应该有最多10分钟的时间来执行请求。我认为,您更希望添加一些代码来重现问题,这将增加您获得答案的机会。我尝试了imaplib,但无法重现错误。它可以一直执行到请求超时。类型2。问题是,没有(记录在案的)方法来设置套接字的超时。事实上,据文件记载,默认情况下套接字没有超时。所以我不明白为什么我的一些请求会在60秒内超时。一个谷歌的家伙说事实上imap端口被阻塞了。。。我试图访问gmail帐户,但没有收到IMAP4_SSL错误。如果您的imap服务器是gmail,请尝试: