Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python 3.6中从HTTPResponse到str_Python_Json_Api_Vimeo - Fatal编程技术网

在Python 3.6中从HTTPResponse到str

在Python 3.6中从HTTPResponse到str,python,json,api,vimeo,Python,Json,Api,Vimeo,从对VimeoAPI的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中,我找到并尝试了以

从对VimeoAPI的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')
但没有一个成功

请问你能帮忙吗


谢谢

尝试使用请求模块

import requests
import json 

r=requests.post('https://api.vimeo.com/oauth/authorize/client?grant_type=client_credentials', varData,  headers={'Authorization': 'basic XXX'})
response = json.loads(r.text)

尝试使用请求模块

import requests
import json 

r=requests.post('https://api.vimeo.com/oauth/authorize/client?grant_type=client_credentials', varData,  headers={'Authorization': 'basic XXX'})
response = json.loads(r.text)
来自(我的):

class http.client.HTTPResponse(sock,debuglevel=0,method=None,url=None)

类,其实例在成功连接时返回不由用户直接实例化。

而且:

另请参见建议将Requests包用于更高级别的HTTP客户端接口

所以你最好直接使用

发出请求后,只需使用(我的)中的
json.loads(r.text)

class http.client.HTTPResponse(sock,debuglevel=0,method=None,url=None)

类,其实例在成功连接时返回不由用户直接实例化。

而且:

另请参见建议将Requests包用于更高级别的HTTP客户端接口

所以你最好直接使用


发出请求后,只需使用
json.loads(r.text)

use可以使用http.client模块。例如:

import http.client
import json
conn = http.client.HTTPConnection('https://api.vimeo.com/oauth/authorize/client?grant_type=client_credentials')
headers = {'Authorization': 'basic XXX'}
params = varData
conn.request('POST', '', params, headers)
response = conn.getresponse()
content = bytes.decode(response.read(), 'utf-8') #return string value
res_map = json.loads(content) #if content is json string

有关更多信息,请参阅:

使用可以使用http.client模块。例如:

import http.client
import json
conn = http.client.HTTPConnection('https://api.vimeo.com/oauth/authorize/client?grant_type=client_credentials')
headers = {'Authorization': 'basic XXX'}
params = varData
conn.request('POST', '', params, headers)
response = conn.getresponse()
content = bytes.decode(response.read(), 'utf-8') #return string value
res_map = json.loads(content) #if content is json string

有关更多信息,请参阅:

是否没有
r.text
r.body
属性?
dir(r)
Hi@RSHAP no r.text或r.body属性的输出是什么。dir(r)的输出是['CONTENT_DECODERS'、'REDIRECT_Status'、'abstractmethods'、'class'、'del'、'delattr'、'dir'、'doc'、'enter'、'eq'、'exit'、'format'、'ge'、'getattribute'、'gt'、'hash'、'init'、'init_subclass'、'iter'、'le'、'lt'、'module'、'ne'、'new'、'next'、'reduce'、'reduce_-lasshook',[…]是否没有
r.text
r.body
属性?dir(r)Hi@RSHAP no r.text或r.body属性的输出是什么。dir(r)的输出是['CONTENT_DECODERS'、'REDIRECT_Status'、'abstractmethods'、'class'、'del'、'delattr'、'dir'、'doc'、'enter'、'eq'、'exit'、'format'、'ge'、'getattribute'、'gt'、'hash'、'init'、'init_subclass'、'iter'、'le'、'lt'、'module'、'ne'、'new'、'next'、'reduce'、'reduce_-套索',[…]