【发布时间】:2019-07-21 14:04:31
【问题描述】:
我最近开始研究 Python 中的 requests 模块,遇到了使用 data={something} 向网站发送数据的 POST 方法。所以,我很好奇并尝试向 google.com 发送帖子,并想看看我的如果我想搜索'hello',则返回结果。我总是收到405 错误。我想知道为什么会收到此错误,甚至有没有办法向用户必须填写一些数据的任何网站发送 POST 请求?
我知道我也可以使用GET,但我特别想使用 POST。
我在下面使用了这段代码。
import requests
data={'q':'hello'}
headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0'}
p_resp=requests.post('https://www.google.com/',headers=headers,data=data)
print(p_resp.text)
我收到了405 error The request method POST is inappropriate for the URL。
【问题讨论】:
标签: python-3.x post python-requests