gpt4 book ai didi

Python - 使用请求发送发布消息

转载 作者:太空宇宙 更新时间:2023-11-03 15:10:28 26 4
gpt4 key购买 nike

我使用 Postman 向捷星网站发送原始请求以获取航类详细信息。我想使用 python 脚本通过请求库做同样的事情,但我无法得到正确的响应。

这是我在 Postman 中所做的:

enter image description here

还有一个我用来发送 post 请求的简单脚本:

import requests
files = {'file': open('PostContent.txt', 'rb')}
if __name__ == "__name__"):
url = "http://www.jetstar.com/"
r = requests.post(url, files = files)
print(r.text)

当我运行 python 脚本时,我总是看到欢迎页面,而不是航类详细信息。我不确定错误是什么?

注意:当我搜索航类时,PostContent.txt 包含原始文本中的表单数据。

当我搜索特定的航类日期时,我使用 Chrome 开发工具来捕获 POST 请求。它是标题中的表单数据。 enter image description here

最佳答案

尝试使用字典而不是文件。 FILE 应该用于发布 FILE,而不是 FORM-ENCODED 帖子,这可能是网站所期望的。

payload = {
'DropDownListCurrency': 'SGD'
}
r = requests.post("http://httpbin.org/post", data=payload)

关于Python - 使用请求发送发布消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27458204/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com