Я пытаюсь использовать запросы к mimi c логин для https://www.recreation.gov/. Для этого я сначала выясняю детали запроса с помощью chrome inspect, а именно:
Request URL: https://www.recreation.gov/api/accounts/login
Request Method: POST
Status Code: 200
Remote Address: 1.2.3.4
Referrer Policy: no-referrer-when-downgrade
request header:
:authority: www.recreation.gov
:method: POST
:path: /api/accounts/login
:scheme: https
:accept: application/json, text/plain, */*
:accept-encoding: gzip, deflate, br
:accept-language: en-US,en;q=0.9
:cache-control: no-cache, no-store, must-revalidate
:content-length: 70
:content-type: application/json;charset=UTF-8
:cookie: alongcookie
:origin: https://www.recreation.gov
:pragma: no-cache
:referer: https://www.recreation.gov/
:sec-fetch-mode: cors
:sec-fetch-site: same-origin
:user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
request payload:
{'username': 'myusername', 'password': 'mypassword'}
Вот мой код:
headers = {
"authority": "www.recreation.gov",
"method":"POST",
"scheme": "https",
"accept": "application/json, text/plain, */*",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9",
"cache-control": "no-cache, no-store, must-revalidate",
"content-length": "70",
"content-type": "application/json;charset=UTF-8",
"origin": "https://www.recreation.gov",
"referer":"https://www.recreation.gov/",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36'
}
with requests.Session() as s:
s.headers = headers
url = 'https://www.recreation.gov/api/accounts/login'
payload = {'username': 'myusername', 'password': 'mypassword'}
response = s.post(url, data=payload)
print(response)
Но я всегда получал :
403 Запрещено
\ nЗапрос запрещен административными правилами. \ N