当前位置: 首页>>代码示例>>Python>>正文


Python httplib.REQUEST_TIMEOUT属性代码示例

本文整理汇总了Python中httplib.REQUEST_TIMEOUT属性的典型用法代码示例。如果您正苦于以下问题:Python httplib.REQUEST_TIMEOUT属性的具体用法?Python httplib.REQUEST_TIMEOUT怎么用?Python httplib.REQUEST_TIMEOUT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在httplib的用法示例。


在下文中一共展示了httplib.REQUEST_TIMEOUT属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import REQUEST_TIMEOUT [as 别名]
def post(self):  # pylint:disable-msg=invalid-name
    """Handles HTTP POST requests."""
    repo_url = self.request.data.get('repo_url')
    if not repo_url:
      Abort(httplib.BAD_REQUEST, 'repo_url required')
    repo = model.GetRepo(repo_url)
    if not repo:
      html_url = name = description = repo_url
      repo = model.CreateRepoAsync(owner=model.GetManualTemplateOwner(),
                                   repo_url=repo_url,
                                   html_url=html_url,
                                   name=name,
                                   description=description,
                                   show_files=[],
                                   read_only_files=[],
                                   read_only_demo_url=None)
    template_project = repo.project.get()
    if not template_project or template_project.in_progress_task_name:
      Abort(httplib.REQUEST_TIMEOUT,
            'Sorry. Requested template is not yet available. '
            'Please try again in 30 seconds.')
    expiration_seconds = self.request.data.get('expiration_seconds')
    project = model.CopyProject(self.user, template_project, expiration_seconds,
                                new_project_name=template_project.project_name)
    return self.DictOfProject(project) 
开发者ID:googlearchive,项目名称:cloud-playground,代码行数:27,代码来源:playground.py

示例2: _should_retry

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import REQUEST_TIMEOUT [as 别名]
def _should_retry(resp):
  """Given a urlfetch response, decide whether to retry that request."""
  return (resp.status_code == httplib.REQUEST_TIMEOUT or
          (resp.status_code >= 500 and
           resp.status_code < 600)) 
开发者ID:googlearchive,项目名称:billing-export-python,代码行数:7,代码来源:api_utils.py

示例3: timed_out

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import REQUEST_TIMEOUT [as 别名]
def timed_out(self):
    return self.__http_response.http_code in [httplib.REQUEST_TIMEOUT,
                                              httplib.GATEWAY_TIMEOUT] 
开发者ID:google,项目名称:citest,代码行数:5,代码来源:http_agent.py

示例4: check_status

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import REQUEST_TIMEOUT [as 别名]
def check_status(status, expected, path, headers=None,
                 resp_headers=None, extras=None):
  """Check HTTP response status is expected.

  Args:
    status: HTTP response status. int.
    expected: a list of expected statuses. A list of ints.
    path: filename or a path prefix.
    headers: HTTP request headers.
    resp_headers: HTTP response headers.
    extras: extra info to be logged verbatim if error occurs.

  Raises:
    AuthorizationError: if authorization failed.
    NotFoundError: if an object that's expected to exist doesn't.
    TimeoutError: if HTTP request timed out.
    ServerError: if server experienced some errors.
    FatalError: if any other unexpected errors occurred.
  """
  if status in expected:
    return

  msg = ('Expect status %r from Google Storage. But got status %d.\n'
         'Path: %r.\n'
         'Request headers: %r.\n'
         'Response headers: %r.\n'
         'Extra info: %r.\n' %
         (expected, status, path, headers, resp_headers, extras))

  if status == httplib.UNAUTHORIZED:
    raise AuthorizationError(msg)
  elif status == httplib.FORBIDDEN:
    raise ForbiddenError(msg)
  elif status == httplib.NOT_FOUND:
    raise NotFoundError(msg)
  elif status == httplib.REQUEST_TIMEOUT:
    raise TimeoutError(msg)
  elif status == httplib.REQUESTED_RANGE_NOT_SATISFIABLE:
    raise InvalidRange(msg)
  elif status >= 500:
    raise ServerError(msg)
  else:
    raise FatalError(msg) 
开发者ID:googlearchive,项目名称:billing-export-python,代码行数:45,代码来源:errors.py

示例5: check_status

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import REQUEST_TIMEOUT [as 别名]
def check_status(status, expected, path, headers=None,
                 resp_headers=None, body=None, extras=None):
  """Check HTTP response status is expected.

  Args:
    status: HTTP response status. int.
    expected: a list of expected statuses. A list of ints.
    path: filename or a path prefix.
    headers: HTTP request headers.
    resp_headers: HTTP response headers.
    body: HTTP response body.
    extras: extra info to be logged verbatim if error occurs.

  Raises:
    AuthorizationError: if authorization failed.
    NotFoundError: if an object that's expected to exist doesn't.
    TimeoutError: if HTTP request timed out.
    ServerError: if server experienced some errors.
    FatalError: if any other unexpected errors occurred.
  """
  if status in expected:
    return

  msg = ('Expect status %r from Google Storage. But got status %d.\n'
         'Path: %r.\n'
         'Request headers: %r.\n'
         'Response headers: %r.\n'
         'Body: %r.\n'
         'Extra info: %r.\n' %
         (expected, status, path, headers, resp_headers, body, extras))

  if status == httplib.UNAUTHORIZED:
    raise AuthorizationError(msg)
  elif status == httplib.FORBIDDEN:
    raise ForbiddenError(msg)
  elif status == httplib.NOT_FOUND:
    raise NotFoundError(msg)
  elif status == httplib.REQUEST_TIMEOUT:
    raise TimeoutError(msg)
  elif status == httplib.REQUESTED_RANGE_NOT_SATISFIABLE:
    raise InvalidRange(msg)
  elif (status == httplib.OK and 308 in expected and
        httplib.OK not in expected):
    raise FileClosedError(msg)
  elif status >= 500:
    raise ServerError(msg)
  else:
    raise FatalError(msg) 
开发者ID:einaregilsson,项目名称:MyLife,代码行数:50,代码来源:errors.py


注:本文中的httplib.REQUEST_TIMEOUT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。