我尝试使用以下代码从 jupyter 笔记本查询 Wigle API,但不断收到以下错误:
HTTPError:401 客户端错误:未经授权的网址:https://api.wigle.net/api/v2/network/search?onlymine=false&freenet=false&paynet=false&ssidlike=Marriott
我怀疑它与身份验证有关,但在 Wigle 的文档页面中,我没有看到/理解在哪里包含我的 api 密钥。任何帮助将不胜感激。
下面的代码是我尝试过的:
import requests
import json
ssidlike = "Marriott"
url = f"https://api.wigle.net/api/v2/network/search?onlymine=false&freenet=false&paynet=false&ssidlike={ssidlike}"
response = requests.get(url)
response.raise_for_status()
if response.status_code != 204:
return response.json()
我期望收到上述查询的 JSON 返回,但结果是以下错误:
HTTPError:401客户端错误:未经授权的网址:https://api.wigle.net/api/v2/network/search?onlymine=false&freenet=false&paynet=false&ssidlike=Marriott
您需要 WiGLE.net 帐户凭据(API 名称和令牌可在 https://wigle.net/account 获得)以便对请求进行身份验证 - 然后使用 python requests basic auth:
response = requests.get(url, auth=('<API Name from above>','<API Token from above>'))