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

Discussão em 'Python' iniciado por Stack, Abril 10, 2025.

  1. Stack

    Stack Membro Participativo

    Mouser is a website where electronic components can be bought and are listed with their details and technical parameters.

    To automate the search of parts from this website, I am trying to automate the processing using the Mouser API Key for part search.

    I am trying to retrieve Part Number details from mouser.com using API key. But, I get no search results. Below is the python script for the same.


    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))


    The output I get is:

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


    If I remove the verify=False, I get following error

    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)')))


    Is there some other version/procedure to get the part details.

    Continue reading...

Compartilhe esta Página