错误403:未授权提供的身份验证访问此资源

发布于 2025-02-11 20:34:50 字数 4550 浏览 0 评论 0原文

我想向以下URL发送发布请求并获得结果。

https://www.snapptrip.com/flights/THR-tehran/KIH-kish-island?roundTrip=false&adultCount=1&childCount=0&inLapCount=0&date=2022-07-01&cabinType=E

为此,我从浏览器中复制了所有标题和cookie,并将它们设置为如下:

import json

import requests
        header = {
    'accept': 'application/json, text/plain, */*',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'en-US,en;q=0.9',
    'cache-control': 'no-cache',
    'content-length': '147',
    'content-type': 'application/json;charset=UTF-8',
    'cookie': 'route=1656317791.775.282.960981; _gcl_au=1.1.2046258357.1656317792; analytics_campaign={%22source%22:%22google%22%2C%22medium%22:%22organic%22}; analytics_token=42b8404c-38bc-f45a-5da5-4b0a9d8d64d3; _yngt_iframe=1; _yngt=7cf79f92-2a8e5-5857f-fc332-20702cb6182a1; _gid=GA1.2.1347682050.1656317794; _hjSessionUser_1680486=eyJpZCI6IjI4YzJkNDgxLWQ5ZmMtNTE0ZC04ODZmLWY0YmU4YWUzZTY0MyIsImNyZWF0ZWQiOjE2NTYzMTgwMjQwOTgsImV4aXN0aW5nIjp0cnVlfQ==; CustomerKey=c6daab9d-76a3-318b-9dc4-a998b9aa3d77; _clck=11btp2n|1|f2q|0; analytics_session_token=6fd59170-a4ac-3fe4-48c2-6672506db682; yektanet_session_last_activity=6/29/2022; _6193bae56a6d2e30f5357d82=true; _hjIncludedInSessionSample=0; _hjSession_1680486=eyJpZCI6IjhlNGU0MWQ4LThmM2QtNGQyNy05YjY2LTRmMDViYTQzYjM3ZCIsImNyZWF0ZWQiOjE2NTY0NzgwOTM2NTUsImluU2FtcGxlIjpmYWxzZX0=; _hjAbsoluteSessionInProgress=0; crisp-client%2Fsession%2Fdb7f3f50-c4be-4ec3-85f9-24c3cff11750=session_8eb3f713-17e8-4046-ad90-ecec16421bed; marketingData={"utm_medium":"","utm_campaign":"","utm_source":"","utm_content":"","utm_term":"","referrer":"https://www.snapptrip.com/flights/THR-tehran/MHD-mashhad?date=2022-08-22&returnDate=&roundTrip=false&adultCount=1&childCount=0&inLapCount=0&cabinType=E"}; flightMarketingData={"utm_medium":"","utm_campaign":"","utm_source":"","utm_content":"","utm_term":"","referrer":"https://www.snapptrip.com/flights/THR-tehran/MHD-mashhad?date=2022-08-22&returnDate=&roundTrip=false&adultCount=1&childCount=0&inLapCount=0&cabinType=E"}; destinationCity=%D9%85%D8%B4%D9%87%D8%AF; _gat_UA-107687430-1=1; _ga_DKJN1PETDV=GS1.1.1656478091.3.1.1656480799.49; _ga=GA1.2.312049892.1656317793; _clsk=1bf2oby|1656480801280|29|1|h.clarity.ms/collect',
    'origin': 'https://www.snapptrip.com',
    'pragma': 'no-cache',
    'referer': ' https://www.snapptrip.com/flights/THR-tehran/MHD-mashhad?roundTrip=false&adultCount=1&childCount=0&inLapCount=0&date=2022-06-30&cabinType=E',
    'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': 'Linux',
    'sec-fetch-dest': 'empty',
    '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/100.0.4896.88 Safari/537.36',
    'x-access-token': '26a53f65-4702-4f99-a5d3-ed03e03ca6e6',
    'x-customer-key': 'c6daab9d-76a3-318b-9dc4-a998b9aa3d77',
    'x-request-id': 'Bearer db312b1422dc4ec4f657de5909612a238af4592d5c25828cccb5bb319090fbf8.e7cf77e7-1d36-489d-9df3-ada35364681e',
    'x-session-id': '3cfbed40-7932-46ee-9513-f342813be7c3',
    'x-user-id': '71d3efa6-6d61-4d3d-89b2-16f1e1a201a1',
}
data = {"origin": "THR", "destination": "MHD", "roundTrip": false,
        "passengers": {"adults": 1, "children": 0, "infants": 0}, "cabinType": "E", "departDate": "2022-06-30"}

url = 'https://www.snapptrip.com/flights/THR-tehran/KIH-kish-island?roundTrip=false&adultCount=1&childCount=0&inLapCount=0&date=2022-07-01&cabinType=E'
res = requests.post(url=url, json=json.dumps(data), headers=header)

浏览器中的标题和曲奇图像如下:

”在此处输入图像说明”

毕竟,它会引发以下错误:

403: The supplied authentication is not authorized to access this resource

I want to send a POST request to the following URL and get the result.

https://www.snapptrip.com/flights/THR-tehran/KIH-kish-island?roundTrip=false&adultCount=1&childCount=0&inLapCount=0&date=2022-07-01&cabinType=E

To do this I have copied all headers and cookies from browser and set them like as follows:

import json

import requests
        header = {
    'accept': 'application/json, text/plain, */*',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'en-US,en;q=0.9',
    'cache-control': 'no-cache',
    'content-length': '147',
    'content-type': 'application/json;charset=UTF-8',
    'cookie': 'route=1656317791.775.282.960981; _gcl_au=1.1.2046258357.1656317792; analytics_campaign={%22source%22:%22google%22%2C%22medium%22:%22organic%22}; analytics_token=42b8404c-38bc-f45a-5da5-4b0a9d8d64d3; _yngt_iframe=1; _yngt=7cf79f92-2a8e5-5857f-fc332-20702cb6182a1; _gid=GA1.2.1347682050.1656317794; _hjSessionUser_1680486=eyJpZCI6IjI4YzJkNDgxLWQ5ZmMtNTE0ZC04ODZmLWY0YmU4YWUzZTY0MyIsImNyZWF0ZWQiOjE2NTYzMTgwMjQwOTgsImV4aXN0aW5nIjp0cnVlfQ==; CustomerKey=c6daab9d-76a3-318b-9dc4-a998b9aa3d77; _clck=11btp2n|1|f2q|0; analytics_session_token=6fd59170-a4ac-3fe4-48c2-6672506db682; yektanet_session_last_activity=6/29/2022; _6193bae56a6d2e30f5357d82=true; _hjIncludedInSessionSample=0; _hjSession_1680486=eyJpZCI6IjhlNGU0MWQ4LThmM2QtNGQyNy05YjY2LTRmMDViYTQzYjM3ZCIsImNyZWF0ZWQiOjE2NTY0NzgwOTM2NTUsImluU2FtcGxlIjpmYWxzZX0=; _hjAbsoluteSessionInProgress=0; crisp-client%2Fsession%2Fdb7f3f50-c4be-4ec3-85f9-24c3cff11750=session_8eb3f713-17e8-4046-ad90-ecec16421bed; marketingData={"utm_medium":"","utm_campaign":"","utm_source":"","utm_content":"","utm_term":"","referrer":"https://www.snapptrip.com/flights/THR-tehran/MHD-mashhad?date=2022-08-22&returnDate=&roundTrip=false&adultCount=1&childCount=0&inLapCount=0&cabinType=E"}; flightMarketingData={"utm_medium":"","utm_campaign":"","utm_source":"","utm_content":"","utm_term":"","referrer":"https://www.snapptrip.com/flights/THR-tehran/MHD-mashhad?date=2022-08-22&returnDate=&roundTrip=false&adultCount=1&childCount=0&inLapCount=0&cabinType=E"}; destinationCity=%D9%85%D8%B4%D9%87%D8%AF; _gat_UA-107687430-1=1; _ga_DKJN1PETDV=GS1.1.1656478091.3.1.1656480799.49; _ga=GA1.2.312049892.1656317793; _clsk=1bf2oby|1656480801280|29|1|h.clarity.ms/collect',
    'origin': 'https://www.snapptrip.com',
    'pragma': 'no-cache',
    'referer': ' https://www.snapptrip.com/flights/THR-tehran/MHD-mashhad?roundTrip=false&adultCount=1&childCount=0&inLapCount=0&date=2022-06-30&cabinType=E',
    'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': 'Linux',
    'sec-fetch-dest': 'empty',
    '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/100.0.4896.88 Safari/537.36',
    'x-access-token': '26a53f65-4702-4f99-a5d3-ed03e03ca6e6',
    'x-customer-key': 'c6daab9d-76a3-318b-9dc4-a998b9aa3d77',
    'x-request-id': 'Bearer db312b1422dc4ec4f657de5909612a238af4592d5c25828cccb5bb319090fbf8.e7cf77e7-1d36-489d-9df3-ada35364681e',
    'x-session-id': '3cfbed40-7932-46ee-9513-f342813be7c3',
    'x-user-id': '71d3efa6-6d61-4d3d-89b2-16f1e1a201a1',
}
data = {"origin": "THR", "destination": "MHD", "roundTrip": false,
        "passengers": {"adults": 1, "children": 0, "infants": 0}, "cabinType": "E", "departDate": "2022-06-30"}

url = 'https://www.snapptrip.com/flights/THR-tehran/KIH-kish-island?roundTrip=false&adultCount=1&childCount=0&inLapCount=0&date=2022-07-01&cabinType=E'
res = requests.post(url=url, json=json.dumps(data), headers=header)

The header and cookie images in the browser are as follows:
enter image description here
enter image description here

enter image description here
enter image description here

After all, it throws following error:

403: The supplied authentication is not authorized to access this resource

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文