从POST请求到Vimeo API,我得到一个编码为HTTPResponse的JSON对象。从HTTPResponse到Python 3.6中的str
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
Hi @RSHAP no r.text or r.body attributes。 DIR(r)的输出是 [ 'CONTENT_DECODERS', 'REDIRECT_STATUSES', '__abstractmethods__', '__class__', '__del__', '__delattr__', '__dict__', '__DIR__', ' __doc__ ' '__enter__', '__eq__', '__exit__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', ' __init_subclass__', '__iter__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__next__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', [...] – Gusepo