首页 > 解决方案 > POST 请求给出错误但我给出所有标题和表单数据

问题描述

我正在尝试抓取一个网站,要求提供登录表单;我正在使用requestspython 3.x 模块。我提供 form_data 和 headers 信息,就像我可以在 Network Google Chrome 开发者控制台上分析的一样:

Payload = {
'form_data': {
    'login': 'MYLOGIN',
    'password': 'MYPASSWORD'},
'headers': {
    'Accept': '*/*',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Origin': 'https://tastyworks.com',
    'Referer': 'https://tastyworks.com/',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
},
'url': 'https://tastyworks.com'

}

post_response = requests.post(
    Payload['url'], data=Payload['form_data'], headers=Payload['headers'])

当我想在 post_response这里打印时,我得到的是:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 

"http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>403 ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
This distribution is not configured to allow the HTTP request method that was used for this request. The distribution supports only cachable requests.

<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: YZ_tAajXFCioe5_fh6sVX4A4aPA_kSICtzKf2pkT76sPPj2R_WiOJg==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>

这是网络分析:响应 这是授权问题吗?或者这与我如何配置请求有关?

多谢你们 :)

标签: pythonpostpython-requests

解决方案


推荐阅读