繁体   English   中英

使用 API 时没有搜索结果 密钥使用 Python 检索信息

[英]No search results while using API Key to retrieve information using Python

Mouser 是一个可以购买电子元器件并列出其详细信息和技术参数的网站。

为了自动从该网站搜索零件,我尝试使用Mouser API Key for part search自动进行处理。

我正在尝试使用 API 密钥从mouser.com检索部件号详细信息。 但是,我没有得到任何搜索结果。 下面是相同的 python 脚本。


import requests
import json

api_key = "my API Key"
part_number = "LM258AMDREP" #Part Number

headers = {
    "Content-Type": "application/json",
    "Accept": "application/json"
}

data = {
    "SearchByPartnumberRequest": {
        "MouserPartNumber": part_number
    }
}

url = f"https://api.mouser.com/api/v1/search/partnumber?apikey={api_key}"

try:
    response = requests.post(url, headers=headers, json=data, verify=False)
    response.raise_for_status()
    data = response.json()
    print(data)
except requests.exceptions.HTTPError as err:
    print ("Error: " + str(err))
except requests.exceptions.RequestException as e:
    # catastrophic error. bail.
    print ("Error: " + str(e))

我得到的 output 是:

{'Errors': [{'Id': 0, 'Code': 'Required', 'Message': 'Required', 'ResourceKey': 'Required', 'ResourceFormatString': None, 
'ResourceFormatString2': None, 'PropertyName': 'Request'}], 'SearchResults': None}

如果我删除verify=False ,我会收到以下错误

Error: HTTPSConnectionPool(host='api.mouser.com', port=443): Max retries exceeded with url: /api/v1/search/partnumber?apikey=e9226156-491c-4635-bfcd-5285f80244cf (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] 
certificate verify failed: self signed certificate in certificate chain (_ssl.c:992)')))

是否有其他版本/程序来获取零件详细信息。

原因默认验证设置为 True

查看文档

暂无
暂无

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

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