Python+请求发送有效负载+报头

2024-10-03 15:31:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从一个Web应用程序中获取一些数据,以便在报告中使用它,这里是Python代码

import requests
import json
url2 ="https://admin.XXXXXbeta.net/#exec-reports"
#this is the data for the login part
 payload {"apiKey":"877070gEt8t8","username":"aXXXX@XXXXX.XXXXXbeta.net","password":"XXXXXXX","timestamp":"1449666522626"}

这是报告部分的数据

^{pr2}$

下面是输出:

{'Server':'XXXXX','Content Type':'text/plain',Connection':'close','Transfer Encoding':'chunked','X-FRAME-OPTIONS':'SAMEORIGIN','Date':'2015年12月14日星期一11:46:15 GMT'} 400 意外字符(“d”(代码100)):应为有效值(数字、字符串、数组、对象、“true”、“false”或“null”) 在[来源:信道qos.logback.access.servlet.TeeServletInputStream@1df260b;行:1,列:2]

进程结束,退出代码为0

我认为问题可能是有效载荷没有按正确的顺序发送有什么想法吗? 谢谢


Tags: the数据代码httpsimportwebjson应用程序
1条回答
网友
1楼 · 发布于 2024-10-03 15:31:18

请求docs

Typically, you want to send some form-encoded data — much like an HTML form. To do this, simply pass a dictionary to the data argument. Your dictionary of data will automatically be form-encoded when the request is made

您的content-type头是"Content-Type":"application/json",您发送的是表单编码的数据。在

如果要以json格式发送数据,请使用类似于:

import json
Arr = Req.post(Url3,data=json.dumps(Payload2),headers=reqHed )

相关问题 更多 >