本文整理汇总了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)
示例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
示例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)
示例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]
示例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
示例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)
示例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)
示例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)
示例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')