简体   繁体   中英

Python: POST request status code 200 not allowing json conversion

import requests
import json

URL = 'https://zoom.us/oauth/token?grant_type=authorization_code&code=XXXXXXXXXXXX&redirect_uri=https://XXXXXX.com'


clientParams= "Basic Q2xpZW50X0lEOkNsaWVudF9TZWNyZXQ=CLIENT_ID:CLIENT_SECRET"
r = requests.post(URL, headers = {'Authorization':clientParams})

data = r.json()

So while r.status_code will return 200, r.json() will throw errors.

Output:

Traceback (most recent call last):
  File "ZoomScript.py", line 10, in <module>
    r.json()
  File "C:\Users\jasonb\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\models.py", line 898, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Users\jasonb\AppData\Local\Programs\Python\Python38-32\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Users\jasonb\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\jasonb\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

here's the first few lines of r.content output

b'<!doctype html>\n<html xmlns:fb="http://ogp.me/ns/fb#" lang="en-US" >\n<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# zoomvideocall: http://ogp.me/ns/fb/zoomvideocall#">\n<title>Error - Zoom</title>\n<meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1">\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8"

This is the expected json response

{
  "access_token": "eyJhbGciOiJI",
  "token_type": "bearer",
  "refresh_token": "eyJhbGciOiJIUzUxM",
  "expires_in": 3599,
  "scope": "user:read:admin"
}

Relevant link for the oauth flow I am trying to work to (This is step 2): https://marketplace.zoom.us/docs/guides/auth/oauth

To me this seems like there is a redirect happening. Maybe just delete &redirect_uri=https://XXXXXX.com from URL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM