【发布时间】:2018-01-07 06:23:24
【问题描述】:
从对 Vimeo API 的 POST 请求,我得到一个编码为 HTTPResponse 的 JSON 对象。
r = http.request('POST', 'https://api.vimeo.com/oauth/authorize/client?grant_type=client_credentials', headers={'Authorization': 'basic XXX'})
我没有找到将 HTTPResponse 转换为 str 或 Json 对象的方法。在stackoverflow中,我发现并尝试了以下选项:
json.loads(r.decode('utf-8'))
json.loads(r.readall().decode('utf-8'))
str(r, 'utf-8')
但它们都不起作用。
你能帮忙吗?
谢谢
【问题讨论】:
-
没有
r.text或r.body属性吗?dir(r)的输出是什么 -
嗨@RSHAP 没有 r.text 或 r.body 属性。 dir(r) 的输出是 ['CONTENT_DECODERS', 'REDIRECT_STATUSES', 'abstractmethods', 'class', 'del', 'delattr', 'dict', 'dir', 'doc', 'enter', 'eq', '退出', '格式', 'ge', ' getattribute', 'gt', 'hash', 'init', 'init_subclass', 'iter', 'le', 'lt', '模块', 'ne', 'new', 'next', 'reduce', 'reduce_ex', 'repr', 'setattr', 'sizeof', 'str', '子类挂钩',[...]