我试图使用POST请求向网站提交一个文件(test.exe(,但它的响应不是正常的302,而是500。我不知道我可以在请求中更改什么:也许是在标头或文件格式中,也许我需要以某种方式传递数据参数?
如果有任何建议,我将不胜感激!
import requests
url = "https://cuckoo.cert.ee/submit/api/presubmit"
files = {"test.exe": open("test.exe", "rb")}
headers = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9",
"Connection": "keep-alive",
"Content-Length": "199",
"Content-Type": "multipart/form-data; boundary=----WebKitFormBoundarymoUA16cLBrh9JNGC",
"Cookie": "csrftoken=O9tFpNhZuZrj7DsEnBAcj0wmV00z8qE3; theme=cyborg; csrftoken=O9tFpNhZuZrj7DsEnBAcj0wmV00z8qE3",
"Host": "cuckoo.cert.ee",
"Origin": "https://cuckoo.cert.ee",
"Referer": "https://cuckoo.cert.ee/submit/",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "Windows",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36",
"X-CSRFToken": "O9tFpNhZuZrj7DsEnBAcj0wmV00z8qE3"
}
response = requests.post(url, headers=headers, files=files, verify=False)
print(response)
可能尝试将内容类型更改为application/octet-stream
。500错误表示网站可能无法处理您试图上传的文件。这可能只是网站出现故障或出现暂时故障。如果你可以访问后端日志,我建议你查看一下,或者联系网站,看看他们是否有任何建议。
编辑:验证您的内容是否与您声明的长度匹配,看起来您的请求中声明了一个内容长度参数。试着把它拿出来看看是否有帮助。