本文整理汇总了Python中wheezy.http.HTTPResponse.write_bytes方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPResponse.write_bytes方法的具体用法?Python HTTPResponse.write_bytes怎么用?Python HTTPResponse.write_bytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wheezy.http.HTTPResponse
的用法示例。
在下文中一共展示了HTTPResponse.write_bytes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from wheezy.http import HTTPResponse [as 别名]
# 或者: from wheezy.http.HTTPResponse import write_bytes [as 别名]
def post(self):
try:
form = self.request.form
code = form["code"][0]
except:
return bad_request_with_detail("No data posted, or data in incorrect format")
params = {"grant_type": "authorization_code", "redirect_uri": config.SPOTIFY_CALLBACK_URL, "code": code}
token_response = requests.post(config.SPOTIFY_TOKEN_ENDPOINT, data=params, headers=auth_header, verify=True)
response = HTTPResponse()
response.content_type = "application/json"
response.status_code = token_response.status_code
if token_response.status_code == 200:
json_response = token_response.json()
refresh_token = json_response["refresh_token"]
encrypted_token = crypt.encrypt(refresh_token)
json_response["refresh_token"] = encrypted_token
response_body = json.dumps(json_response)
response.write(response_body)
else:
response.write_bytes(token_response.content)
return response
示例2: get
# 需要导入模块: from wheezy.http import HTTPResponse [as 别名]
# 或者: from wheezy.http.HTTPResponse import write_bytes [as 别名]
def get(self, skip_body=False):
mime_type, encoding = mimetypes.guess_type(self.filepath)
response = HTTPResponse(mime_type or 'plain/text', encoding)
if not skip_body:
response.headers.append(HTTP_HEADER_ACCEPT_RANGE_NONE)
file = open(self.filepath, 'rb')
try:
response.write_bytes(file.read())
finally:
file.close()
return response
示例3: _error_response
# 需要导入模块: from wheezy.http import HTTPResponse [as 别名]
# 或者: from wheezy.http.HTTPResponse import write_bytes [as 别名]
def _error_response(self, request, error):
resp = HTTPResponse()
resp.status_code = ERROR_STATUS_CODE
resp.write_bytes(json.dumps({'error': error}))
return resp