如果我有r.json,我会得到一个Response [200],但当我有r.json()时,事情变得很奇怪。我对这个非常新,所以任何和所有的提示都欢迎!在chromdev工具的payload选项卡下找到了一个不同的键,还有一些我尝试插入的东西,比如“animal_ids”
此代码:
data = {"key":api_key, "cookie": cookie, "start_date": date1.strftime('20%y-%m-%dT00:00:00-07:00'),
"end_date": date2.strftime('20%y-%m-%dT00:00:00-07:00'), "animal_ids": animal_ids
}
r = requests.post(url, data=data)
return r.json()
print(icons())
产量:
Traceback (most recent call last):
File "C:\Users\geiss\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\geiss\AppData\Local\Programs\Python\Python311\Lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\geiss\AppData\Local\Programs\Python\Python311\Lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\geiss\AppData\Local\Programs\Python\Python311\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)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\geiss\postreq.py", line 17, in <module>
print(icons())
^^^^^^^
File "C:\Users\geiss\postreq.py", line 16, in icons
return r.json()
^^^^^^^^
File "C:\Users\geiss\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
预期收益率(这是一个json,不是吗?):
{
"success": true,
"error": false,
"data": {
"animals": {
"9488": {
"icons": [
{
"id": null,
"animal_id": "9488",
"color_label_template_id": "27",
"comment": "Can open gates 12\/8\/21",
"created_at": "1638992225",
"created_by": "120",
"edited_at": null,
"edited_by": null,
"is_deleted": "0",
"deleted_at": null,
"deleted_by": null,
"fontawesome_icon_id": "1495",
"color_label_template_group_id": null,
"title": "Opens Gates",
"color": "#ff792f",
"capacity": null,
"checkout_alert": "0",
"checkin_alert": "1",
"reservation_creation_alert": "0",
"owner_details_alert": "0",
"animal_details_alert": "0",
"reservation_details_alert": "0",
"class": "fa fa-surprise",
"is_pro": "0",
"name": null,
"location_id": null,
"animal_color_label_id": "8341",
"type": "custom"
},
{
"id": null,
"animal_id": "9488",
"color_label_template_id": "38",
"comment": "see employee notes",
"created_at": "1639781526",
"created_by": "137",
"edited_at": null,
"edited_by": null,
"is_deleted": "0",
"deleted_at": null,
"deleted_by": null,
"fontawesome_icon_id": "173",
"color_label_template_group_id": null,
"title": "Grooming",
"color": "#16537e",
"capacity": null,
"checkout_alert": "0",
"checkin_alert": "1",
"reservation_creation_alert": "1",
"owner_details_alert": "0",
"animal_details_alert": "1",
"reservation_details_alert": "1",
"class": "fa fa-scissors",
"is_pro": "0",
"name": null,
"location_id": null,
"animal_color_label_id": "8461",
"type": "custom"
},
如果有帮助的话,我特别尝试拉“评论”和“标题”
1条答案
按热度按时间bgibtngc1#
尝试改变
到
对于POST请求,有效载荷将被传递给
json
参数,而不是data
。