本文整理匯總了Python中tornado.httpclient.HTTPError方法的典型用法代碼示例。如果您正苦於以下問題:Python httpclient.HTTPError方法的具體用法?Python httpclient.HTTPError怎麽用?Python httpclient.HTTPError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tornado.httpclient
的用法示例。
在下文中一共展示了httpclient.HTTPError方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _handle_exception
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPError [as 別名]
def _handle_exception(self, typ, value, tb):
if self.final_callback:
self._remove_timeout()
if isinstance(value, StreamClosedError):
if value.real_error is None:
value = HTTPError(599, "Stream closed")
else:
value = value.real_error
self._run_callback(HTTPResponse(self.request, 599, error=value,
request_time=self.io_loop.time() - self.start_time,
))
if hasattr(self, "stream"):
# TODO: this may cause a StreamClosedError to be raised
# by the connection's Future. Should we cancel the
# connection more gracefully?
self.stream.close()
return True
else:
# If our callback has already been called, we are probably
# catching an exception that is not caused by us but rather
# some child of our callback. Rather than drop it on the floor,
# pass it along, unless it's just the stream being closed.
return isinstance(value, StreamClosedError)
示例2: AllocateIds
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPError [as 別名]
def AllocateIds(asset_types, user_cookie):
http_headers = {
'Cookie': '_xsrf=fake_xsrf; user=%s' % user_cookie,
'X-XSRFToken': 'fake_xsrf',
'Content-Type': 'application/json'
}
body = {
'headers': {
'version': MAX_SUPPORTED_MESSAGE_VERSION
},
'asset_types': asset_types
}
try:
response = _CallService('/service/allocate_ids', body, http_headers)
except HTTPError:
return None
else:
return json.loads(response.body)
示例3: TerminateUser
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPError [as 別名]
def TerminateUser(info_dict, login_resp):
http_headers = {
'Cookie': '_xsrf=fake_xsrf; user=%s' % login_resp['cookie'],
'X-XSRFToken': 'fake_xsrf',
'Content-Type': 'application/json'
}
body = {
'headers': login_resp['headers'],
}
op_id = AllocateIds(['o'], login_resp['cookie'])
if op_id is not None:
body['headers']['op_id'] = op_id['asset_ids'][0]
try:
response = _CallService('/service/terminate_account', body, http_headers)
except HTTPError:
return None;
else:
return json.loads(response.body)
示例4: test_app_auth_with_invalid_pubkey_for_user_robey
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPError [as 別名]
def test_app_auth_with_invalid_pubkey_for_user_robey(self):
url = self.get_url('/')
privatekey = 'h' * 1024
files = [('privatekey', 'user_rsa_key', privatekey)]
content_type, body = encode_multipart_formdata(self.body_dict.items(),
files)
headers = {
'Content-Type': content_type, 'content-length': str(len(body))
}
if swallow_http_errors:
response = yield self.async_post(url, body, headers=headers)
self.assertIn(b'Invalid key', response.body)
else:
with self.assertRaises(HTTPError) as ctx:
yield self.async_post(url, body, headers=headers)
self.assertIn('Bad Request', ctx.exception.message)
示例5: test_app_auth_with_pubkey_exceeds_key_max_size
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPError [as 別名]
def test_app_auth_with_pubkey_exceeds_key_max_size(self):
url = self.get_url('/')
privatekey = 'h' * (handler.PrivateKey.max_length + 1)
files = [('privatekey', 'user_rsa_key', privatekey)]
content_type, body = encode_multipart_formdata(self.body_dict.items(),
files)
headers = {
'Content-Type': content_type, 'content-length': str(len(body))
}
if swallow_http_errors:
response = yield self.async_post(url, body, headers=headers)
self.assertIn(b'Invalid key', response.body)
else:
with self.assertRaises(HTTPError) as ctx:
yield self.async_post(url, body, headers=headers)
self.assertIn('Bad Request', ctx.exception.message)
示例6: test_app_auth_with_pubkey_cannot_be_decoded_by_multipart_form
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPError [as 別名]
def test_app_auth_with_pubkey_cannot_be_decoded_by_multipart_form(self):
url = self.get_url('/')
privatekey = 'h' * 1024
files = [('privatekey', 'user_rsa_key', privatekey)]
content_type, body = encode_multipart_formdata(self.body_dict.items(),
files)
body = body.encode('utf-8')
# added some gbk bytes to the privatekey, make it cannot be decoded
body = body[:-100] + b'\xb4\xed\xce\xf3' + body[-100:]
headers = {
'Content-Type': content_type, 'content-length': str(len(body))
}
if swallow_http_errors:
response = yield self.async_post(url, body, headers=headers)
self.assertIn(b'Invalid unicode', response.body)
else:
with self.assertRaises(HTTPError) as ctx:
yield self.async_post(url, body, headers=headers)
self.assertIn('Bad Request', ctx.exception.message)
示例7: _get_dmm_token
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPError [as 別名]
def _get_dmm_token(self):
try:
req = yield self.http_client.fetch(dmm.LOGIN_URL, headers=self.headers,
connect_timeout=self.connect_timeout,
request_timeout=self.request_timeout,
proxy_host=proxy_host, proxy_port=proxy_port)
except (CurlError, HTTPError):
raise OoiAuthError('連接DMM網站失敗')
body = native_str(req.body)
m = self.dmm_token_pattern.search(body)
if m:
dmm_token = m.group(1)
else:
raise OoiAuthError('獲取DMM token失敗')
m = self.token_pattern.search(body)
if m:
token = m.group(1)
else:
raise OoiAuthError('獲取token失敗')
return dmm_token, token
示例8: _get_ajax_token
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPError [as 別名]
def _get_ajax_token(self, dmm_token, token):
self.headers.update({'Origin': 'https://www.dmm.com',
'Referer': dmm.LOGIN_URL,
'Cookie': 'ckcy=1; check_open_login=1; check_down_login=1',
'DMM_TOKEN': dmm_token,
'X-Requested-With': 'XMLHttpRequest'})
body = urlencode({'token': token})
try:
req = yield self.http_client.fetch(dmm.AJAX_TOKEN_URL, method='POST', headers=self.headers, body=body,
connect_timeout=self.connect_timeout,
request_timeout=self.request_timeout,
proxy_host=proxy_host, proxy_port=proxy_port)
except (CurlError, HTTPError):
raise OoiAuthError('DMM網站AJAX請求失敗')
j = json_decode(native_str(req.body))
return j['token'], j['login_id'], j['password']
示例9: _get_world
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPError [as 別名]
def _get_world(self, osapi_url):
qs = parse_qs(urlparse(osapi_url).query)
owner = qs['owner'][0]
self.owner = owner
st = qs['st'][0]
url = dmm.GET_WORLD_URL % (owner, int(time.time()*1000))
self.headers['Referer'] = osapi_url
try:
req = yield self.http_client.fetch(url, headers=self.headers,
connect_timeout=self.connect_timeout,
request_timeout=self.request_timeout,
proxy_host=proxy_host, proxy_port=proxy_port)
except (CurlError, HTTPError):
raise OoiAuthError('獲取服務器ID失敗')
svdata = json_decode(native_str(req.body)[7:])
if svdata['api_result'] == 1:
world_id = svdata['api_data']['api_world_id']
else:
raise OoiAuthError('服務器ID錯誤')
return world_id, st
示例10: proxy_package
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPError [as 別名]
def proxy_package(cls, package):
try:
remote_package_exists = yield PYPIClient.exists(package)
if remote_package_exists:
pkg_real_name = yield PYPIClient.find_real_name(package)
pkg = yield proxy_remote_package(pkg_real_name)
raise Return(pkg)
raise LookupError("Remote package not found")
except (LookupError, HTTPClientError) as e:
if isinstance(e, HTTPClientError):
log.warning("PYPI backend return an error: %s", e)
raise Return(Package.find(package))
示例11: check_access
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPError [as 別名]
def check_access(handler, roleneed):
if isinstance(roleneed,MasterRoleNeed):
return
if not roleneed:
raise HTTPError(403)
checkname = handler.__checkname__
if handler.__needcheck__.get('url',None):
if not checkname in roleneed.nodes:
raise HTTPError(403)
ctx_params = handler.__needcheck__.get('ctx_param',None)
if ctx_params:
for ctx_param in ctx_params.split(','):
ctx_val = handler.get_argument(ctx_param, handler.path_kwargs.get(ctx_param,None))
if not ctx_val in roleneed.ctx_vals.get(ctx_param,()):
raise HTTPError(403)
示例12: _request
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPError [as 別名]
def _request(self, callback, request):
try:
response = yield self.client.fetch(request)
except httpclient.HTTPError as e:
if e.code == 599:
raise base.Timeout
response = e.response
raise gen.Return(callback(self.response(response)))
示例13: _on_timeout
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPError [as 別名]
def _on_timeout(self, key):
request, callback, timeout_handle = self.waiting[key]
self.queue.remove((key, request, callback))
timeout_response = HTTPResponse(
request, 599, error=HTTPError(599, "Timeout"),
request_time=self.io_loop.time() - request.start_time)
self.io_loop.add_callback(callback, timeout_response)
del self.waiting[key]
示例14: on_connection_close
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPError [as 別名]
def on_connection_close(self):
if self.final_callback is not None:
message = "Connection closed"
if self.stream.error:
raise self.stream.error
try:
raise HTTPError(599, message)
except HTTPError:
self._handle_exception(*sys.exc_info())
示例15: test_websocket_http_fail
# 需要導入模塊: from tornado import httpclient [as 別名]
# 或者: from tornado.httpclient import HTTPError [as 別名]
def test_websocket_http_fail(self):
with self.assertRaises(HTTPError) as cm:
yield self.ws_connect('/notfound')
self.assertEqual(cm.exception.code, 404)