繁体   English   中英

API 请求在 Web 站点中有效,但在 python 请求中无效

[英]API requests works in the Web site But not work in python requests

我 go 到这个网页上

https://iso19139echnap.geocat.live/geonetwork/doc/api/index.html#/records/getRecord

并在 Records/get/get a metadata record 下尝试这个 API 调用。

在此处输入图像描述

工作过,

在此处输入图像描述

但是,如果我尝试在 python 中调用 API,它会响应403

import requests
url_metadata = "https://iso19139echnap.geocat.live/geonetwork/srv/api/0.1/records/d1ec996c-d21c-4bc4-9888-6f1722b44a57"

headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,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",
"Connection": "keep-alive",
"Cookie": "XSRF-TOKEN=97bb29dd-9165-4fd4-bbd1-e2c72bffa509; JSESSIONID=78C1024AF960D630A4EA49DA02DFC89A; serverTime=1615580729954; sessionExpiry=1615582829954",
"Host": "iso19139echnap.geocat.live",
"Referer": "https://iso19139echnap.geocat.live/geonetwork/doc/api/index.html",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36 Edg/89.0.774.45",
"Sec-Fetch-User": "?1",
"Upgrade-Insecure-Requests": "1",
    }
payload = {}


r_metadata = requests.request("GET", url_metadata, headers=headers, data=payload)
print("single metadata api status: "+ str(r_metadata))

这是一个身份验证问题,您需要将X-XSRF-TOKEN包含为 header。 请参阅此答案,了解如何从 API 客户端向 GeoNetwork 发送请求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM