我正在尝试获取this Postman Collection请求以在aiohttp中运行,但无法这样做。它可以很好地在Postman中运行并显示数据。您可以使用此URL自己进行测试。
这是我要使用的Python代码。
async def test2():
url = 'https://nationalpark.mahaonline.gov.in/User/Availability.aspx'
data = {'__EVENTTARGET': 'ctl00$CPH$ddlUtility',
'__VIEWSTATE': '/wEPDwUKLTM3MTY1MTYyMw8WAh4UQWR2YW5jZUJvb2tpbmdMaW1pdHMy9i0AAQAAAP////8BAAAAAAAAAAwCAAAATlN5c3RlbS5EYXRhLCBWZXJzaW9uPTQuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49Yjc3YTVjNTYxOTM0ZTA4OQUBAAAAFVN5c3RlbS5EYXRhLkRhdGFUYWJsZQMAAAAZRGF0YVRhYmxlLlJlbW90aW5nVmVyc2lvbglYbWxTY2hlbWELWG1sRGlmZkdyYW0DAQEOU3lzdGVtLlZlcnNpb24CAAAACQMAAAAGBAAAANMJPD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTE2Ij8+DQo8eHM6c2NoZW1hIHhtbG5zPSIiIHhtbG5zOnhzPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYSIgeG1sbnM6bXNkYXRhPSJ1cm46c2NoZW1hcy1taWNyb3NvZnQtY29tOnhtbC1tc2RhdGEiPg0KICA8eHM6ZWxlbWVudCBuYW1lPSJUYWJsZSI+DQogICAgPHhzOmNvbXBsZXhUeXBlPg0KICAgICAgPHhzOnNlcXVlbmNlPg0KICAgICAgICA8eHM6ZWxlbWVudCBuYW1lPSJGYWNpbGl0eU5hbWUiIHR5cGU9InhzOnN0cmluZyIgbXNkYXRhOnRhcmdldE5hbWVzcGFjZT0iIiBtaW5PY2N1cnM9IjAiIC8+DQogICAgICAgIDx4czplbGVtZW50IG5hbWU9IkZhY2lsaXR5SUQiIHR5cGU9InhzOmxvbmciIG1zZGF0YTp0YXJnZXROYW1lc3BhY2U9IiIgb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ZXB1cm5hIFNhbmN0dWFyeR1UaXBwZXNod2FyIFdpbGRsaWZlIFNhbmN0dWFyeQ1Cb3IgU2FuY3R1YXJ5G1VtcmVkIC0gS2hhcmFuZGxhIFNhbmN0dWFyeRNQZW5jaCBUaWdlciBSZXNlcnZlHk5hd2VnYW9uLW5hZ3ppcmEgVGlnZXIgUmVzZXJ2ZRxUYWRvYmEtQW5kaGFyaSBUaWdlciBSZXNlcnZlDVNhbmpheSBHYW5kaGkdRG55YW5nYW5nYSBXaWxkbGlmZSBTYW5jdHVhcnkVDAtTZWxlY3QgUGFyawIxNwIxNQIxNgE5ATMBOAExATQBNwIxMAIxOBQrAwxnZ2dnZ2dnZ2dnZ2cWAWZkAg0PDxYCHgRUZXh0BQoxOC8xMi8yMDE4ZGQCEQ8PFgQeDE1pbmltdW1WYWx1ZQUKMTgvMTIvMjAxOB4MTWF4aW11bVZhbHVlBQoxNi8wMi8yMDE5ZGRkybkpBLuRAdTkWh3TktFucE1oWb3KywGKNnuGhLjBn6M=',
'__VIEWSTATEGENERATOR': '30B840D6',
'__EVENTVALIDATION': '/wEdABDxLaaFMn9343OqJgSgkmjxBJ/H8P3kqyTkjExcLYtcGFBJ8C8BYpvL+GE7RwGpmWEbT9UBV3A0QjSyFpuERAlPsbNuBpZ6mIWONQrZ3y94fIpZ4AG8JMH0YPGdi4ZIQxS0Z2okfWoC/puMj/NjdYDmvnRn+BR1vSDA/QmOhf5Cm1ZompbG8uV7ojAwvWT4/lu9UBNS8pvWt/F8WfTFWsIJltHawDEmFvU8RGocPTDzHMIQY26emGcQb1cxpnNbPiTxr/HF2Dze+enlf8lhGijlUSZFPS/pmlFL9B08v8KulFPVXOa94et0GZgzkoqys5r/etgpEQvlbp40b8ZuEdj87EJXln9UnM2m0Lqiz0btC+gFkdY7fN74leFlSsHifgY=',
'ctl00$CPH$ddlUtility:': '17',
'ctl00$CPH$txtDate': '18/12/2018'
}
headers = {'Content-Type': "application/x-www-form-urlencoded"}
async with aiohttp.ClientSession() as session:
async with session.get(url, data=data, headers=headers) as resp:
html = await resp.read()
await save_html(html)
async def save_html(html):
os.remove("test3.html")
with open("test3.html", 'wb') as f:
f.write(html)
def main():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(test2())
两种情况下返回的HTML均不同。我已经从Postman中删除了cookie和标题,所以它们不是这里的问题。
我也尝试过处理python请求和请求超时。 我也用http.client尝试过,它也超时。
我这里可能缺少一些基本的东西。