Search code examples
pythonjsonapivimeo

From HTTPResponse to str in Python 3.6


From a POST request to Vimeo API I get a JSON object encoded as HTTPResponse.

r = http.request('POST', 'https://api.vimeo.com/oauth/authorize/client?grant_type=client_credentials', headers={'Authorization': 'basic XXX'})

I do not find a way to convert the HTTPResponse to a str or Json object. In stackoverflow I found and tried the following options:

json.loads(r.decode('utf-8'))

json.loads(r.readall().decode('utf-8'))

str(r, 'utf-8')

but none of them worked.

Please can you help?

Thanks


Solution

  • try with requests module

    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)