発生しているエラー
requests#post()#json()
でjson.decoder.JSONDecodeError
が発生します。(res.json()
でエラーが発生)
こちらを参考にしました。ステータスは200なのになぜでしょうか?
コードとエラー
python
1 def refresh_access_token(self): 2 config = OneDriveTokenJsonAdapter() 3 4 endpoint = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize" 5 6 payload = {"grant_type": "refresh_token", "refresh_token": config.refresh_token, "client_id": config.client_id, 7 "client_secret": config.client_secret, "scope": self.__scope, "redirect_uri": self.__redirect_url} 8 header = {"Content-Type": "application/x-www-form-urlencoded"} 9 res = requests.post(url=endpoint, data=payload, headers=header) 10 print(res.status_code) 11 print(res.json())
出力
bash
1200 2Traceback (most recent call last): 3 File "C:/Users/-/PycharmProjects/PixivDrive/RequestAccessToken.py", line 67, in <module> 4 main() 5 File "C:/Users/-/PycharmProjects/PixivDrive/RequestAccessToken.py", line 63, in main 6 request.refresh_access_token() 7 File "C:/Users/-/PycharmProjects/PixivDrive/RequestAccessToken.py", line 52, in refresh_access_token 8 print(res.json()) 9 File "C:\Users\-\Anaconda3\envs\pixivpy\lib\site-packages\requests\models.py", line 892, in json 10 return complexjson.loads(self.text, **kwargs) 11 File "C:\Users\-\Anaconda3\envs\pixivpy\lib\json\__init__.py", line 354, in loads 12 return _default_decoder.decode(s) 13 File "C:\Users\-\Anaconda3\envs\pixivpy\lib\json\decoder.py", line 339, in decode 14 obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 15 File "C:\Users\-\Anaconda3\envs\pixivpy\lib\json\decoder.py", line 357, in raw_decode 16 raise JSONDecodeError("Expecting value", s, err.value) from None 17json.decoder.JSONDecodeError: Expecting value: line 3 column 1 (char 4) 18
自分で調べたこと
res.request.body
でBodyの中身を確認した所None
でした。この場合何がいけないんでしょうか?因みに、ツールの方でhttpリクエストは成功して、トークンを取得できてます。
長いので省略してます
print(res.content)
b'\r\n\r\n<!DOCTYPE html>\r\n<html dir="ltr" class="" lang="en">\r\n<head>\r\n <title>Sign in to your account</title>\r\n
print(res.text)
python
1 2 3 4<!DOCTYPE html> 5<html dir="ltr" class="" lang="en"> 6<head> 7 <title>Sign in to your account</title>
回答1件
あなたの回答
tips
プレビュー