首页 > 解决方案 > 无法在未获得响应 [500] 的情况下模拟浏览器 POST 请求。为什么?

问题描述

import requests

url = 'https://cmoffice.kenes.com/cmsearchableprogrammev15/conferencemanager/CM_W3_SearchableProgram/api/persionid/anonymous/type/normal/getfilteredsessions/conference/igcs19'

headers = {'accept': '*/*',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en-GB,en-US;q=0.9,en;q=0.8',
'content-type': 'application/json; charset=UTF-8',
'cookie': '_ga=GA1.2.471841928.1549896884; _gid=GA1.2.1479150813.1563120868; __RequestVerificationToken_L2NtU2VhcmNoYWJsZVByb2dyYW1tZVYxNQ2=t57HyXHVNBIm0HZ33v1WyG8hRa4j4RlDEOvFtEfPakPgH5AutBjAN5pSRHnBx_BpBhbMnH6R-tIhSdop_VMtLF-aY7XcXTRFt7vg5X46zgE1; _gat=1',
'origin': 'https://cmoffice.kenes.com',
'referer': 'https://cmoffice.kenes.com/cmsearchableprogrammeV15/conferencemanager/programme/personid/anonymous/igcs19/normal/b833d15f547f3cf698a5e922754684fa334885ed',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
'x-requested-with': 'XMLHttpRequest'}

response = requests.post(url, headers = headers)

print(response)

给出响应 [500]

但是,浏览器能够获得带有 status_code 200 的 json 响应

谁能阐明为什么以及如何解决这个问题?

标签: pythonpython-requests

解决方案


后端似乎有些不对劲。当您尝试向其发布时,它会返回 500,这实际上可能是诸如缺少配置或编程错误之类的东西。

如果我在浏览器中点击给定的 URL,我实际上会收到 405 'method not allowed' 错误。


推荐阅读