Python请求Post请求失败403禁止
我正在尝试使用请求登录到位于的帐户 但当我试图发送我从chrome复制的相同帖子时: 通过会话,但我得到一个403错误Python请求Post请求失败403禁止,python,python-3.x,session,post,bots,Python,Python 3.x,Session,Post,Bots,我正在尝试使用请求登录到位于的帐户 但当我试图发送我从chrome复制的相同帖子时: 通过会话,但我得到一个403错误 <HTML><HEAD> <TITLE>Access Denied</TITLE> </HEAD><BODY> <H1>Access Denied</H1> You don't have permission to access "http:&
<HTML><HEAD>
<TITLE>Access Denied</TITLE>
</HEAD><BODY>
<H1>Access Denied</H1>
You don't have permission to access "http://accounts.marshalls.com/accounts.login" on this server.<P>
Reference #18.5eb72d17.1605497585.72bc8e0
</BODY>
</HTML>
有一些psuedo头文件是我在会话中使用的hypers适配器,但我想知道这是否不是预期的工作方式。如何测试我是否发送了http20
import requests
from hyper.contrib import HTTP20Adapter
def login():
s = requests.Session()
headers={
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.9',
'Cache-Control': 'max-age=0',
'Connection': 'keep-alive',
'Referer': 'https://www.marshalls.com/',
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-User': '?1',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
}
get = s.get('https://www.marshalls.com/us/store/account/login.jsp', headers=headers)
headersLogin = {
':authority': 'accounts.marshalls.com',
':method': 'POST',
':path': '/accounts.login',
':scheme': 'https',
'accept': '*/*',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en-US,en;q=0.9',
'content-length': '399',
'content-type': 'application/x-www-form-urlencoded',
'referer': 'https://www.marshalls.com',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
}
payload = {
'loginID': 'myemail',
'password': 'mypassword',
'sessionExpiration': '0',
'targetEnv': 'jssdk',
'include': 'profile,data,emails,subscriptions,preferences,',
'includeUserInfo': 'true',
'loginMode': 'standard',
'lang': 'en',
'APIKey': '3_84HOWqumMAkoaSVTqQNoCAALdj3OntNUdrwyVkECGt4AP7soziO3WwvTWEHcvtRB',
'source': 'showScreenSet',
'sdk': 'js_latest',
'authMode': 'cookie',
'pageURL': 'https://www.marshalls.com/us/store/index.jsp',
'format': 'json'
}
s.mount('https://accounts.marshalls.com/', HTTP20Adapter())
page1 = s.post('https://accounts.marshalls.com/accounts.login', headers=headersLogin, data=payload)
print(page1.text)