Python/Javascript中的Api密钥请求

2024-10-05 14:22:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试向API发出请求。我已经拿到了API密钥并阅读了文档

文件:https://info.nobil.no/images/downloads/API-NOBIL-Documentation_v3_20180808.pdf

在我看来,文档中的示例似乎是用javascript编写的

 jQuery.ajax({
 type: 'POST',
 url: 'https://nobil.no/api/server/search.php',
data: { 'apikey': nobilApiKey, 'apiversion': '3',
'action': "search",
 'type': 'rectangle',
 'northeast': '(59.943921193288915, 10.826683044433594)',
 'southwest': '(59.883683240905256, 10.650901794433594)',
'existingids': '189,195,199,89,48'},
 dataType: 'json'
});    

问题: 1.)我可以用python向服务器发出请求吗? 2.)如何将api密钥输入到代码中

如果你能给我一个代码片段来说明你是如何做到的,我将不胜感激


Tags: 文件no代码文档httpsinfoapisearch
1条回答
网友
1楼 · 发布于 2024-10-05 14:22:22

您将使用requests

它看起来像这样:

import requests
url = 'https://nobil.no/api/server/search.php?mode=ajax'
post_data = { 'apikey': nobilApiKey, 'apiversion': '3',
'action': "search",
 'type': 'rectangle',
 'northeast': '(59.943921193288915, 10.826683044433594)',
 'southwest': '(59.883683240905256, 10.650901794433594)',
'existingids': '189,195,199,89,48'}
r = requests.post(url, data=post_data)
# do something with r

请阅读此处的文档:https://requests.readthedocs.io/en/master/

相关问题 更多 >