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


Python urlfetch.Error方法代码示例

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


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

示例1: request

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import Error [as 别名]
def request(self, method, url, headers, post_data=None):
        try:
            result = urlfetch.fetch(
                url=url,
                method=method,
                headers=headers,
                # Google App Engine doesn't let us specify our own cert bundle.
                # However, that's ok because the CA bundle they use recognizes
                # api.stripe.com.
                validate_certificate=self._verify_ssl_certs,
                # GAE requests time out after 60 seconds, so make sure we leave
                # some time for the application to handle a slow Stripe
                deadline=55,
                payload=post_data
            )
        except urlfetch.Error, e:
            self._handle_request_error(e, url) 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:19,代码来源:http_client.py

示例2: request

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import Error [as 别名]
def request(self, method, url, headers, post_data=None):
        try:
            result = urlfetch.fetch(
                url=url,
                method=method,
                headers=headers,
                # Google App Engine doesn't let us specify our own cert bundle.
                # However, that's ok because the CA bundle they use recognizes
                # api.goshippo.com.
                validate_certificate=self._verify_ssl_certs,
                # GAE requests time out after 60 seconds, so make sure we leave
                # some time for the application to handle a slow Shippo
                deadline=55,
                payload=post_data
            )
        except urlfetch.Error as e:
            self._handle_request_error(e, url)

        return result.content, result.status_code 
开发者ID:goshippo,项目名称:shippo-python-client,代码行数:21,代码来源:http_client.py

示例3: test_retries_transient_errors

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import Error [as 别名]
def test_retries_transient_errors(self):
    self.mock_urlfetch([
        ({
            'url': 'http://localhost/123'
        }, urlfetch.Error()),
        ({
            'url': 'http://localhost/123'
        }, Response(408, 'clien timeout', {})),
        ({
            'url': 'http://localhost/123'
        }, Response(500, 'server error', {})),
        ({
            'url': 'http://localhost/123'
        }, Response(200, 'response body', {})),
    ])
    response = net.request('http://localhost/123', max_attempts=4)
    self.assertEqual('response body', response) 
开发者ID:luci,项目名称:luci-py,代码行数:19,代码来源:net_test.py

示例4: get

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import Error [as 别名]
def get(self):
        # [START urlfetch-get]
        url = 'http://www.google.com/humans.txt'
        try:
            result = urlfetch.fetch(url)
            if result.status_code == 200:
                self.response.write(result.content)
            else:
                self.response.status_code = result.status_code
        except urlfetch.Error:
            logging.exception('Caught exception fetching url')
        # [END urlfetch-get] 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:14,代码来源:main.py

示例5: __init__

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import Error [as 别名]
def __init__(self, msg, status_code, response, headers=None):
    super(Error, self).__init__(msg)
    self.status_code = status_code
    self.headers = headers
    self.response = response 
开发者ID:luci,项目名称:luci-py,代码行数:7,代码来源:net.py

示例6: _fetch_service_certs

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import Error [as 别名]
def _fetch_service_certs(service_url):
  protocol = 'https://'
  if utils.is_local_dev_server():
    protocol = ('http://', 'https://')
  assert service_url.startswith(protocol), (service_url, protocol)
  url = '%s/auth/api/v1/server/certificates' % service_url

  # Retry code is adapted from components/net.py. net.py can't be used directly
  # since it depends on components.auth (and dependency cycles between
  # components are bad).
  attempt = 0
  result = None
  while attempt < 4:
    if attempt:
      logging.info('Retrying...')
    attempt += 1
    logging.info('GET %s', url)
    try:
      result = urlfetch.fetch(
          url=url,
          method='GET',
          headers={'X-URLFetch-Service-Id': utils.get_urlfetch_service_id()},
          follow_redirects=False,
          deadline=5,
          validate_certificate=True)
    except (apiproxy_errors.DeadlineExceededError, urlfetch.Error) as e:
      # Transient network error or URL fetch service RPC deadline.
      logging.warning('GET %s failed: %s', url, e)
      continue
    # It MUST return 200 on success, it can't return 403, 404 or >=500.
    if result.status_code != 200:
      logging.warning(
          'GET %s failed, HTTP %d: %r', url, result.status_code, result.content)
      continue
    return json.loads(result.content)

  # All attempts failed, give up.
  msg = 'Failed to grab public certs from %s (HTTP code %s)' % (
      service_url, result.status_code if result else '???')
  raise CertificateError(msg, transient=True) 
开发者ID:luci,项目名称:luci-py,代码行数:42,代码来源:signature.py

示例7: test_call_async_transient_error

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import Error [as 别名]
def test_call_async_transient_error(self):
    calls = self.mock_urlfetch([
      {
        'url': 'http://example.com',
        'payload': 'blah',
        'method': 'POST',
        'headers': {'A': 'a'},
        'response': (500, {'error': 'zzz'}),
      },
      {
        'url': 'http://example.com',
        'payload': 'blah',
        'method': 'POST',
        'headers': {'A': 'a'},
        'response': urlfetch.Error('blah'),
      },
      {
        'url': 'http://example.com',
        'payload': 'blah',
        'method': 'POST',
        'headers': {'A': 'a'},
        'response': (200, {'abc': 'def'}),
      },
    ])
    response = service_account._call_async(
        url='http://example.com',
        payload='blah',
        method='POST',
        headers={'A': 'a'}).get_result()
    self.assertEqual({'abc': 'def'}, response)
    self.assertFalse(calls) 
开发者ID:luci,项目名称:luci-py,代码行数:33,代码来源:service_account_test.py

示例8: test_gives_up_retrying

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import Error [as 别名]
def test_gives_up_retrying(self):
    self.mock_urlfetch([
        ({
            'url': 'http://localhost/123'
        }, Response(500, 'server error', {})),
        ({
            'url': 'http://localhost/123'
        }, Response(500, 'server error', {})),
        ({
            'url': 'http://localhost/123'
        }, Response(200, 'response body', {})),
    ])
    with self.assertRaises(net.Error):
      net.request('http://localhost/123', max_attempts=2) 
开发者ID:luci,项目名称:luci-py,代码行数:16,代码来源:net_test.py

示例9: test_json_bad_response

# 需要导入模块: from google.appengine.api import urlfetch [as 别名]
# 或者: from google.appengine.api.urlfetch import Error [as 别名]
def test_json_bad_response(self):
    self.mock_urlfetch([
        ({
            'url': 'http://localhost/123'
        }, Response(200, 'not a json', {})),
    ])
    with self.assertRaises(net.Error):
      net.json_request('http://localhost/123') 
开发者ID:luci,项目名称:luci-py,代码行数:10,代码来源:net_test.py


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