実現したいこと
pythonによるAPI利用(メソッドPOST)で、bodyを取得したい
この質問は、「この回答はGPT-4による自動生成回答」を踏まえ、再度、質問内容を変更したものです。
前提
・データベースで、APIキーを購入し、欲しい条件の施設のID番号を取得するタスクがあります。
・ソースコード実行で、ステータスコードが200が得られました。この意味は、「データ取得できています」を示します。
・必要なbody(リクエストパラメータサンプル)は以下のイメージです。
"result":[
"37.×××,138.×××",#施設IDの緯度、経度
"38.×××,139.×××",
"40.×××,140.75221",
"42.×××,138.×××",
],
発生している問題・エラーメッセージ
修正コードで実行したら、JSONDecodeError: [Errno Expecting value] となりました。
200 --------------------------------------------------------------------------- JSONDecodeError Traceback (most recent call last) /usr/local/lib/python3.10/dist-packages/requests/models.py in json(self, **kwargs) 909 try: --> 910 return complexjson.loads(self.text, **kwargs) 911 except JSONDecodeError as e: 4 frames JSONDecodeError: Expecting value: line 1 column 1 (char 0) During handling of the above exception, another exception occurred: JSONDecodeError Traceback (most recent call last) /usr/local/lib/python3.10/dist-packages/requests/models.py in json(self, **kwargs) 915 raise RequestsJSONDecodeError(e.message) 916 else: --> 917 raise RequestsJSONDecodeError(e.msg, e.doc, e.pos) 918 919 @property JSONDecodeError: [Errno Expecting value] <!DOCTYPE html>
該当のソースコード
python3
1import requests 2import json 3 4url = "https://xxxxxxxxxxx/api/xx/xxxx/xxxx/report/2021/" 5headers = {'api-key': '〇〇〇〇〇〇', 'Content-Type': 'application/json'} 6 7data = { 8 "querys":[ 9 { 10 "key":"area_value", 11 "value":"××(施設の該当箇所のエリア)", 12 "op":"7" 13 }, 14 { 15 "key":"office_value", 16 "value":"××(施設の該当箇所の管理事務所)", 17 "op":"7" 18 } 19 ], 20 "limit":100, 21 "offset":0 22} 23 24res = requests.post(url, headers=headers, data=json.dumps(data)) 25print(res.status_code) 26 27print(res.json()) # レスポンスボディを JSON 形式で出力
試したこと
post、requests、python等をキーワード検索したが、有効な情報が無かった。
この質問は、「この回答はGPT-4による自動生成回答」を踏まえ、再度、質問内容を変更したものです。
補足情報(FW/ツールのバージョンなど)
GoogleColaboratory環境で、pythonで実行

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/06/28 00:37
2023/06/28 01:20
2023/06/28 01:21
2023/06/28 01:54
2023/06/28 13:19