Git Product home page Git Product logo

digikey-api's People

Contributors

aj4ayushjain avatar davepeake avatar funkenjaeger avatar laf0rge avatar makew0rld avatar peeter123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

digikey-api's Issues

Getting a KeyError

I've had some issues with this particular item. Other components work fine but this one: 1690-RASPBERRYPI4B/4GB-ND (digikey part number). This is what I get when trying to run digikey.part function.

digikey.part('1690-RASPBERRYPI4B/4GB-ND')
2020-03-20 10:52:06,656 - digikey.oauth2 - DEBUG: Saved token to: D:\Work\NTS_repos\DigikeyTranslator\token_storage.json
2020-03-20 10:52:07,580 - digikey.decorators - ERROR: Wrapped error: 'x-ratelimit-limit'
Traceback (most recent call last):
File "C:\Program Files (x86)\Python37-32\lib\site-packages\digikey\decorators.py", line 25, in inner
return func(*args, **kwargs)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\retrying.py", line 49, in wrapped_f
return Retrying(*dargs, **dkw).call(f, *args, **kw)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\retrying.py", line 206, in call
return attempt.get(self._wrap_exception)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\retrying.py", line 247, in get
six.reraise(self.value[0], self.value[1], self.value[2])
File "C:\Program Files (x86)\Python37-32\lib\site-packages\six.py", line 693, in reraise
raise value
File "C:\Program Files (x86)\Python37-32\lib\site-packages\retrying.py", line 200, in call
attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\digikey\decorators.py", line 62, in inner
return func(*args, **kwargs)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\digikey\client.py", line 90, in _request_get
rate_limit = re.split('[,;]+', response.headers['x-ratelimit-limit'])[0]
File "C:\Program Files (x86)\Python37-32\lib\site-packages\requests\structures.py", line 52, in getitem
return self._store[key.lower()][1]
KeyError: 'x-ratelimit-limit'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "", line 1, in
File "C:\Program Files (x86)\Python37-32\lib\site-packages\digikey\api.py", line 62, in part
include_for_use_with=include_for_use_with,
File "C:\Program Files (x86)\Python37-32\lib\site-packages\digikey\client.py", line 168, in part
return self._request_get('/Search/v3/Products/{}'.format(partnr), data=params)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\digikey\decorators.py", line 34, in inner
raise exc_type(message) from exc
digikey.exceptions.DigikeyError: KeyError

I've managed to get a proper response from digikey in their developer portal demo (https://developer.digikey.com/products/product-information/partsearch/productdetails?prod=true), so I don't think it's on digikey. I've tried putting time delays and running separately but no success.

About the log-in requirement

Hello Peter,

I have a small question. Every time when I switch to a new computer with digikey-api, I need to log in digikey's website through the browser. I wondered if I can do it via scripts since I want this code to work on the servers.

Thanks for taking your time!
Best,
Runze

OSError: [Errno 98] Address already in use

Hello,

I am new to the OAuth2 stuff, so I'm sure I did something wrong here, but I have my cached .pem files -- however whenever I run the example code from the README, I get this error:

    httpd = HTTPServer(
  File "/usr/lib/python3.8/socketserver.py", line 452, in __init__
    self.server_bind()
  File "/usr/lib/python3.8/http/server.py", line 137, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "/usr/lib/python3.8/socketserver.py", line 466, in server_bind
    self.socket.bind(self.server_address)
OSError: [Errno 98] Address already in use

Any help would be greatly appreciated, I realize this is not a problem with this projects code, but just trying to get through this hurdle

API Limit not working?

Hello,

I tried the example given here.

$ python ./pydigikey.py
TTraceback (most recent call last):
File "./pydigikey.py", line 48, in
result = digikey.keyword_search(body=search_request, api_limits=api_limit)
File "/usr/local/lib/python3.8/site-packages/digikey/v3/api.py", line 77, in keyword_search
return client.call_api_function(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/digikey/v3/api.py", line 64, in call_api_function
api_response = func(*args, self.authorization, self.x_digikey_client_id, **kwargs)
File "/usr/local/lib/python3.8/site-packages/digikey/v3/productinformation/api/part_search_api.py", line 240, in keyword_search_with_http_info
raise TypeError(
TypeError: Got an unexpected keyword argument 'api_limits' to method keyword_search

StoragePath ValueError

by running your default script:

import os
from pathlib import Path

import digikey
from digikey.v3.productinformation import KeywordSearchRequest
from digikey.v3.batchproductdetails import BatchProductDetailsRequest

CACHE_DIR = os.path.join(os.getcwd(), 'dir')

os.environ['DIGIKEY_CLIENT_ID'] = 'DIGIKEY_CLIENT_ID'
os.environ['DIGIKEY_CLIENT_SECRET'] = 'DIGIKEY_CLIENT_SECRET'
os.environ['DIGIKEY_CLIENT_SANDBOX'] = 'True'
os.environ['DIGIKEY_STORAGE_PATH'] = CACHE_DIR
print(os.environ['DIGIKEY_STORAGE_PATH'])

# Query product number
dkpn = '296-6501-1-ND'
part = digikey.product_details(dkpn)

# Search for parts
search_request = KeywordSearchRequest(keywords='CRCW080510K0FKEA', record_count=10)
result = digikey.keyword_search(body=search_request)

# Only if BatchProductDetails endpoint is explicitly enabled
# Search for Batch of Parts/Product
mpn_list = ["0ZCK0050FF2E", "LR1F1K0"] #Length upto 50
batch_request = BatchProductDetailsRequest(products=mpn_list)
part_results = digikey.batch_product_details(body=batch_request)
the output is:
<WORKSPACE>\dir
Traceback (most recent call last):
  File "<WORKSPACE>\d_api.py", line 18, in <module>
    part = digikey.product_details(dkpn)
  File "<USER>\AppData\Local\Programs\Python\Python310\lib\site-packages\digikey\v3\api.py", line 121, in product_details
    client = DigikeyApiWrapper('product_details_with_http_info', digikey.v3.productinformation)
  File "<USER>\AppData\Local\Programs\Python\Python310\lib\site-packages\digikey\v3\api.py", line 55, in __init__
    self._digikeyApiToken = digikey.oauth.oauth2.TokenHandler(version=3, sandbox=self.sandbox).get_access_token()
  File "<USER>\AppData\Local\Programs\Python\Python310\lib\site-packages\digikey\oauth\oauth2.py", line 132, in __init__
    raise ValueError(
ValueError: STORAGE PATH must be set and must exist.Set "DIGIKEY_STORAGE_PATH" as an environment variable, or pass your keys directly to the client.

I tried putting in the actual path, setting an windows environment variable manually in settings and via set, setx, tried https://stackoverflow.com/a/59489965 but output was all the same.

Can't have the V3 example working

Hello,
I've been trying to make the example working from the readme. § Use [API V3]
No chance so far. The python script is stuck.

I have registered a production app, set the callback url on digikey website.
Here is what I got:

$ python ./pydigikey.py
2021-07-08 15:10:23,163 - digikey.oauth.oauth2 - DEBUG: Using API V3
2021-07-08 15:10:23,163 - digikey.oauth.oauth2 - WARNING: Oauth2 token storage does not exist or malformed, creating new.
2021-07-08 15:10:23,163 - digikey.oauth.oauth2 - DEBUG: AUTH - Authenticating with endpoint https://api.digikey.com/v1/oauth2/authorize using ID: wxxxxxxxxxxxxxxxQ...
2021-07-08 15:10:23,163 - digikey.oauth.oauth2 - DEBUG: AUTH - Redirect URL: https://localhost:8139/digikey_callback

Using the python script headless gives issues respawning the browser for OAuth2

I am using the script succesfully in conjuction with a php framework.
I call the script and reply the data in JSON format.

When it needs to re-authorize it should open the browser.

Example:
REFRESH - Failed to use refresh token, starting new authorization flow.

Then i use this in a GUI type call from terminal this works without any issues.
When calling the script from inside my PHP framework, or headless from SSH, it refuses to open the browser and the script is broken.
Is there any way i can resolve this issue ?

OAuth trouble

Hi,

Something is not quite working for me. The browser pops up with the "accept security risk and continue". I click on the button, the code gets displayed on the browser but that's when the problems start.

It prints up to the following line on the terminal, and when I close the browser the rest of errors get printed. Not sure if that's of any help.

IndexError: list index out of range

2023-07-19 23:56:58,269 - digikey.oauth.oauth2 -    DEBUG: Using API V3
2023-07-19 23:56:58,269 - digikey.oauth.oauth2 -  WARNING: Oauth2 token storage does not exist or malformed, creating new.
2023-07-19 23:56:58,269 - digikey.oauth.oauth2 -    DEBUG: AUTH - Authenticating with endpoint https://api.digikey.com/v1/oauth2/authorize using ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxx...
2023-07-19 23:56:58,269 - digikey.oauth.oauth2 -    DEBUG: AUTH - Redirect URL: https://localhost:8139/digikey_callback
Error occurred during loading data. Trying to use cache server https://fake-useragent.herokuapp.com/browsers/0.1.11
Traceback (most recent call last):
  File "/home/gabriel/.pyenv/versions/apps39a/lib/python3.9/site-packages/fake_useragent/utils.py", line 154, in load
    for item in get_browsers(verify_ssl=verify_ssl):
  File "/home/gabriel/.pyenv/versions/apps39a/lib/python3.9/site-packages/fake_useragent/utils.py", line 99, in get_browsers
    html = html.split('<table class="w3-table-all notranslate">')[1]
IndexError: list index out of range
Traceback (most recent call last):
  File "/home/gabriel/.pyenv/versions/apps39a/lib/python3.9/site-packages/fake_useragent/utils.py", line 154, in load
    for item in get_browsers(verify_ssl=verify_ssl):
  File "/home/gabriel/.pyenv/versions/apps39a/lib/python3.9/site-packages/fake_useragent/utils.py", line 99, in get_browsers
    html = html.split('<table class="w3-table-all notranslate">')[1]
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/gabriel/.pyenv/versions/apps39a/lib/python3.9/site-packages/fake_useragent/utils.py", line 64, in get
    with contextlib.closing(urlopen(
  File "/home/gabriel/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "/home/gabriel/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 523, in open
    response = meth(req, response)
  File "/home/gabriel/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 632, in http_response
    response = self.parent.error(
  File "/home/gabriel/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 561, in error
    return self._call_chain(*args)
  File "/home/gabriel/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 494, in _call_chain
    result = func(*args)
  File "/home/gabriel/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 641, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 503: Service Unavailable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/gabriel/Documents/Repositories/inventree-getparts/webcam_example.py", line 16, in <module>
    api = getparts.API(None, debug=False, use_api=True)
  File "/home/gabriel/Documents/Repositories/inventree-getparts/getparts.py", line 68, in __init__
    self.DigikeyAPI = DigikeyAPI(use_api=use_api)
  File "/home/gabriel/Documents/Repositories/inventree-getparts/digikey_API.py", line 8, in __init__
    digikey.product_details()
  File "/home/gabriel/.pyenv/versions/apps39a/lib/python3.9/site-packages/digikey/v3/api.py", line 83, in product_details
    client = ProductApiWrapper('product_details_with_http_info')
  File "/home/gabriel/.pyenv/versions/apps39a/lib/python3.9/site-packages/digikey/v3/api.py", line 39, in __init__
    self._digikeyApiToken = digikey.oauth.oauth2.TokenHandler(version=3, sandbox=self.sandbox).get_access_token()
  File "/home/gabriel/.pyenv/versions/apps39a/lib/python3.9/site-packages/digikey/oauth/oauth2.py", line 277, in get_access_token
    token_json = self.__exchange_for_token(httpd.auth_code)
  File "/home/gabriel/.pyenv/versions/apps39a/lib/python3.9/site-packages/digikey/oauth/oauth2.py", line 164, in __exchange_for_token
    headers = {'user-agent': f'{UserAgent().firefox}',
  File "/home/gabriel/.pyenv/versions/apps39a/lib/python3.9/site-packages/fake_useragent/fake.py", line 69, in __init__
    self.load()
  File "/home/gabriel/.pyenv/versions/apps39a/lib/python3.9/site-packages/fake_useragent/fake.py", line 75, in load
    self.data = load_cached(
  File "/home/gabriel/.pyenv/versions/apps39a/lib/python3.9/site-packages/fake_useragent/utils.py", line 250, in load_cached
    update(path, use_cache_server=use_cache_server, verify_ssl=verify_ssl)
  File "/home/gabriel/.pyenv/versions/apps39a/lib/python3.9/site-packages/fake_useragent/utils.py", line 245, in update
    write(path, load(use_cache_server=use_cache_server, verify_ssl=verify_ssl))
  File "/home/gabriel/.pyenv/versions/apps39a/lib/python3.9/site-packages/fake_useragent/utils.py", line 187, in load
    ret = json.loads(get(
  File "/home/gabriel/.pyenv/versions/apps39a/lib/python3.9/site-packages/fake_useragent/utils.py", line 84, in get
    raise FakeUserAgentError('Maximum amount of retries reached')
fake_useragent.errors.FakeUserAgentError: Maximum amount of retries reached

Can't authenticate

Running the v3 branch, the "use" example in the readme results in
{"ErrorResponseVersion":"3.0.0.0","StatusCode": 401,"ErrorMessage":"Invalid clientId","ErrorDetails":"clientId invalid for requested resource","RequestId":"fae07ab5-88cf-4582-e7df-94d89fb8f9b4","ValidationErrors":[]}

On the page where I'd expect to see a user login. I've checked and double checked that my clientid is valid

Unable to search for a part

Hi!

I'm running a very simple demo based on example in Readme:

import digikey
import sys
import logging
from digikey.v3.productinformation import KeywordSearchRequest

digikey.logger.setLevel(logging.CRITICAL)
query=sys.argv[1]

print(f'searching for \'{query}\'')

search_request = KeywordSearchRequest(keywords=query, record_count=10)
result = digikey.keyword_search(body=search_request)

for res in result.products:
    print(res.product_description)

However, the only thing it prints no matter what I type is:

CAP ALUM 1000UF 20% 35V RADIAL

Enabling debug shows that it tries for the correct query:

2021-08-07 15:47:00,941 - digikey.oauth.oauth2 -    DEBUG: Using API V3
2021-08-07 15:47:00,942 -       digikey.v3.api -     INFO: Search for: 100k 0603
2021-08-07 15:47:00,942 -       digikey.v3.api -    DEBUG: CALL -> keyword_search
2021-08-07 15:47:00,942 -       digikey.v3.api -    DEBUG: CALL wrapped -> PartSearchApi.keyword_search_with_http_info
2021-08-07 15:47:01,672 -       digikey.v3.api -    DEBUG: Requests remaining: [966/1000]

Thanks in advance!

API V2 down for good?

https://api.digikey.com/services/partsearch/v2 returns an error:

{
   "fault":{
      "faultstring":"Unable to identify proxy for host: secure and url: \/services\/partsearch\/v2",
      "detail":{
         "errorcode":"messaging.adaptors.http.flow.ApplicationNotFound"
      }
   }
}

I think we can work towards a V1.0 release which removes the v2 API. This also enables PR #15 to be moved forward.

Token retreival not working when using the code in a server

I'm trying to use the code in an application that runs on a server (inside a docker to be precise).

The problem is that I can't generate the token this way: indeed, the request is made to Digikey by the server, so the webpage of Digikey authorization never displays. I also tried changing the redirect URL to my server address, but same issue.

The only way to make this work is to generate the token on my machine, then upload the token on the server. However, the token has a very limited lifespan.

Looking at the Digikey API, there seems to be a "refresh" token that is valid 90 days, maybe that could do the job?

I also want to thank you for the code, as it helped me a lot :)

Remove distutils

distutils is deprecated and removed since python 3.12. This means that the package can not be used as a dependency in packages that aim to be compatible with python >3.11.
To replace distutils, you can take a look at this SO thread and the referenced Migration Advice. The only use of distutils in your package is in

from distutils.util import strtobool
. Specifically, you're using strtobool. As per the migration advice, strtobool doesn't come with a drop-in replacement and you'll have to reimplement it yourself accordingly. This PR from a different package (I'm sure there's more, that was the first result in my search) does exactly that, so you can get inspired or copy the definition. The specification for strtobool can be found here.

'digikey' is not a package

Hi,

I installed the package with pip in a conda environment. It is visible in anaconda navigator and present in the envirnment directory. With both PyCharm and VSCode I get this message every time i try to run a script that imports digikey:

from digikey.v3.productinformation import KeywordSearchRequest ModuleNotFoundError: No module named 'digikey.v3'; 'digikey' is not a package

I am running the example from the readme. This is probably something easy I am overlooking. Can you help me?

Thanks a lot

Missing parameters in GRM1885C1H560FA01J

Dear All,

I came accross an interesting component : the GRM1885C1H560FA01J on digi-key (490-11467-1-ND)

  • the script output is missing the digi-reel part number (490-11467-6-ND)
  • it it set as "discontinued at digikey", but nothing is indicated on the website (not a big deal, but still interesting) ;)
    could you please have look why the reel information is not given?
    Thank you!

Trouble after DigiKey Update

Hello,
After update the DigiKey page no longer sees "ExcludeMarketPlaceProducts" and "RequestedQuantity" values in our requests in KeywordSearchRequest. Can you check it please and tell what we need to change to solve this problem?

Karavaev Konstantin

Invalid redirect request

I'm trying to use Ki-nTree's digikey function which makes use of this API. It brings up the authentication web page in Google Chrome and when I select to enable the app using my key and URL, https://localhost, I always get the error message:
{"ErrorCode" : "invalid_request", "Error" :"Invalid redirection uri https://localhost:8139/digikey_callback"}

When I run a packet trace, I do not see any attempt to access port 8139 on my localhost from the redirection. I do see traffic to 8139 if I manually attempt to connect a web browser to that URL right after I get the failure message. This indicates that there is something in Google Chrome that is preventing redirection to localhost from working.

Choosing currency and country

Hello my dudes,

I was wondering how to change the currency and the country when doing a ProductDetails call. I found on the DK API website that you can pass the X-DIGIKEY-Locale-Site header and the X-DIGIKEY-Locale-Currency, but I'm not sure how to implement it in the code, since I'm not that great in Python.

Can you help me with that?

Issues with fake-useragent and proxy server

First of all thank you for writing this interface and making it available!
I encountered two issues when setting it up last week and wanted to let you know:

  1. The package 'fake-useragent' seems to be used to generate http user-agent headers. This package seems to be quite 'smart' and uses a 3rd party server for generating these headers.
    Unfortunately there seems to be something broken and the package threw an exception (or the package couldn't handly my proxy settings).
    So I replaced the calls to fake-useragent with static user-agent strings.

  2. I'm in a corporate setting behind a proxy and my system is configured with a proxy path environment variable (Windows). While the Oauth2 mechanism works fine with digikey over the proxy out of the box, the actual requests to the API are always configured to proxy=none.
    So I added to the constructor of the class DigikeyApiWrapper:
    configuration.proxy = os.environ['HTTPS_PROXY']

Now it's working just fine.

Hope that helps!

SSL Cerificate Verify Failed

Error while executing the sample code to get the product details.

Traceback (most recent call last):
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connectionpool.py", line 703,
in urlopen
httplib_response = self._make_request(
^^^^^^^^^^^^^^^^^^^
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connectionpool.py", line 386,
in _make_request
self._validate_conn(conn)
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connectionpool.py", line 1042, in validate_conn
conn.connect()
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connection.py", line 414, in connect
self.sock = ssl_wrap_socket(
^^^^^^^^^^^^^^^^
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\util\ssl
.py", line 449, in ssl_wrap_socket
ssl_sock = ssl_wrap_socket_impl(
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\util\ssl
.py", line 493, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\ssl.py", line 517, in wrap_socket
return self.sslsocket_class._create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\ssl.py", line 1075, in _create
self.do_handshake()
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\ssl.py", line 1346, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:992)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\adapters.py", line 489, in send
resp = conn.urlopen(
^^^^^^^^^^^^^
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\connectionpool.py", line 787,
in urlopen
retries = retries.increment(
^^^^^^^^^^^^^^^^^^
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\site-packages\urllib3\util\retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.digikey.com', port=443): Max retries exceeded with url: /v1/oauth2/token (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:992)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\site-packages\digikey\oauth\oauth2.py", line 172, in __exchange_for_token
r = requests.post(self.token_url, headers=headers, data=post_data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\api.py", line 115, in post
return request("post", url, data=data, json=json, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\sessions.py", line 587, in request
resp = self.send(prep, **send_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\sessions.py", line 701, in send
r = adapter.send(request, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\e0739379\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\adapters.py", line 563, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='api.digikey.com', port=443): Max retries exceeded with url: /v1/oauth2/token (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:992)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\runpy.py", line 198, in _run_module_as_main
return _run_code(code, main_globals, None,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\runpy.py", line 88, in run_code
exec(code, run_globals)
File "c:\Users.vscode\extensions\ms-python.python-2023.2.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy_main
.py", line 39, in
cli.main()
File "c:\Users.vscode\extensions\ms-python.python-2023.2.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\Users.vscode\extensions\ms-python.python-2023.2.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
runpy.run_path(target, run_name="main")
File "c:\Users.vscode\extensions\ms-python.python-2023.2.0\pythonFiles\lib\python\debugpy_vendored\pydevd_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
return _run_module_code(code, init_globals, run_name,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users.vscode\extensions\ms-python.python-2023.2.0\pythonFiles\lib\python\debugpy_vendored\pydevd_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "c:\Users.vscode\extensions\ms-python.python-2023.2.0\pythonFiles\lib\python\debugpy_vendored\pydevd_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
exec(code, run_globals)
File "C:\Users\OneDrive - Danfoss\Desktop\API\DigiKey_API_Search.py", line 14, in
part = digikey.product_details(dkpn)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\e0739379\AppData\Local\Programs\Python\Python311\Lib\site-packages\digikey\v3\api.py", line 121, in product_details
client = DigikeyApiWrapper('product_details_with_http_info', digikey.v3.productinformation)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\site-packages\digikey\v3\api.py", line 55, in init
self._digikeyApiToken = digikey.oauth.oauth2.TokenHandler(version=3, sandbox=self.sandbox).get_access_token()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\site-packages\digikey\oauth\oauth2.py", line 271, in get_access_token
token_json = self.__exchange_for_token(httpd.auth_code)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\site-packages\digikey\oauth\oauth2.py", line 175, in __exchange_for_token
raise DigikeyOauthException('TOKEN - Cannot request new token with auth code: {}'.format(e))
digikey.exceptions.DigikeyOauthException: TOKEN - Cannot request new token with auth code: HTTPSConnectionPool(host='api.digikey.com', port=443): Max retries exceeded with url: /v1/oauth2/token (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:992)')))

AttributeError: 'ManufacturerProductDetailsRequest' object has no attribute 'keywords'

Dear both,

First of all, thank you very much for this API solution.

I wanted to try out the manufacturer_product_details and used the commands below

search_request = ManufacturerProductDetailsRequest(manufacturer_product=part, record_count=10)
manufacturer_details = digikey.manufacturer_product_details(body=search_request)

"part" is set to a manufacturer reference => ERA-3AED681V

The error in the title is given - what am I doing wrong?

Secondly, I noticed the responses from keyword_search and product_details are not iterable.
What is your recommendation to treat the output result (getting all the returned information into a dictionary)?

Thank you very much for your time,
Best,
Peter

API fails in docker app (python 3.9.1)

Hello,

I'm using your API within a docker instance. I do have the following error during execution:

/usr/local/lib/python3.9/site-packages/digikey/v3/api.py, line 110, in manufacturer_product_details
            logger.info(f'Search for: {kwargs["body"].keywords}')

the API is ok with Python 3.8.10 while in docker Python 3.9.1 is run.
Moreover, I had a previous error with this call

digikey.keyword_search(body=search_request, api_limits=api_limit)

api_limits was unknown...
Pip show digikay-api return version 0.4.0.

Product details Quantity on Order always return 0

hello,

ive been working with the digikey api and have been trying to retrieve the quantity on order for parts in my list that are not in stock. i have noticed that a lot of these when checked manually have a quantity on order however, through the api call:

part = digikey_api.product_details(part_number, x_digikey_locale_site='CA', x_digikey_locale_language='en', x_digikey_locale_currency='CAD') print(x.quantity_on_order)

i am always receiving 0. For example with the part: ADT6402SRJZ-RL7 i can see that by checking on the website through the check lead time button there will be some available in jun 2023. is this only a result of now + lead_time?

Issues with example code

Hi Everyone,

I've been trying to use this API, but keep running into this error when running the code below:

I've tried the V3 (ProductInformation) and the V4 (Product Information) to troubleshoot, both have the same error.

The authorization browser window opens but the code crashes straight after

Code:

import os
from pathlib import Path

import digikey
from digikey.v3.productinformation import KeywordSearchRequest
from digikey.v3.batchproductdetails import BatchProductDetailsRequest

CACHE_DIR = Path('path/to/cache/dir')

os.environ['DIGIKEY_CLIENT_ID'] = 'EBfFnLvf0eUfSR9PGTSB5kngims1Ulsp'
os.environ['DIGIKEY_CLIENT_SECRET'] = '0ogUpOFq9Gs0gAk2'
os.environ['DIGIKEY_CLIENT_SANDBOX'] = 'True'
os.environ['DIGIKEY_STORAGE_PATH'] = r'C:\Users\benme\OneDrive\Careers or Jobs\3ADesigns'

# Query product number
dkpn = '296-6501-1-ND'
part = digikey.product_details(dkpn)

# Search for parts
search_request = KeywordSearchRequest(keywords='CRCW080510K0FKEA', record_count=10)
result = digikey.keyword_search(body=search_request)

# Search for Batch of Parts/Product
mpn_list = ["0ZCK0050FF2E", "LR1F1K0"] #Length up to 50
batch_request = BatchProductDetailsRequest(products=mpn_list)
part_results = digikey.batch_product_details(body=batch_request)

Error:

`Oauth2 token storage does not exist or malformed, creating new.
Traceback (most recent call last):
  File "c:\Users\benme\OneDrive\Careers or Jobs\3ADesigns\DigikeyV3.py", line 18, in <module>
    part = digikey.product_details(dkpn)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\benme\AppData\Local\Programs\Python\Python312\Lib\site-packages\digikey\v3\api.py", line 121, in product_details
    client = DigikeyApiWrapper('product_details_with_http_info', digikey.v3.productinformation)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\benme\AppData\Local\Programs\Python\Python312\Lib\site-packages\digikey\v3\api.py", line 55, in __init__
    self._digikeyApiToken = digikey.oauth.oauth2.TokenHandler(version=3, sandbox=self.sandbox).get_access_token()
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\benme\AppData\Local\Programs\Python\Python312\Lib\site-packages\digikey\oauth\oauth2.py", line 255, in get_access_token
    httpd.socket = ssl.wrap_socket(httpd.socket, certfile=str(Path(filename)), server_side=True)
                   ^^^^^^^^^^^^^^^
AttributeError: module 'ssl' has no attribute 'wrap_socket'

Any help would be appreciated,

Thanks very much,

Ben

product_details search: Distinguish between 404 and API failure

Hi,

In performing digikey.product_details(dk_part_number) operation, I am trying to figure out how to distinguish between a 404 (part not found) and a failure of the API to reach digikey/return anything. The return value in both cases is None.

If I search for e.g. an ancient part like 300-8544-1-ND, the following occurs:
2021-10-28 09:57:14,279 - digikey.v3.api - ERROR: Exception when calling product_details_with_http_info: (404) Reason: Not Found HTTP response headers: HTTPHeaderDict({'Date': 'Thu, 28 Oct 2021 13:57:14 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Server': 'Kestrel', 'X-RateLimit-Limit': '1000', 'X-RateLimit-Remaining': '986', 'Access-Control-Allow-Origin': '', 'Access-Control-Allow-Headers': 'origin, x-requested-with, accept, content-type, authorization,x-digikey-client-id, x-digikey-locale-site, x-digikey-locale-language, x-digikey-locale-currency, x-digikey-locale-shiptocountry, x-digikey-customer-id', 'Access-Control-Max-Age': '3628800', 'Access-Control-Allow-Methods': 'GET, POST', 'X-DIGIKEY-REQUEST-ID': '61455b37-5c98-4c13-c530-f081fe27f53f'}) HTTP response body: {"ErrorResponseVersion":"3.0.0.0","StatusCode": 404,"ErrorMessage":"The specified part was not found.","ErrorDetails":"The specified part 300-8544-1-ND was not found","RequestId":"61455b37-5c98-4c13-c530-f081fe27f53f","ValidationErrors":[]}
On the other hand, I occasionally get a long string of errors similar to this:
2021-10-28 09:47:58,750 WARNING Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x0000020EB948A688>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond')': /Search/v3/Products/300-8555-1-ND
and these also return None after failing.

Is there a way to distinguish the two? Or at least get the last status of an API activity to see if it succeeded or failed?

Thank you. I'll post if I find anything of interest.

digikey.status_saleorder_id() returns None

When using the sandbox v3 OrderDetailsApi, I'm getting a valid response to
digikey.salesorder_history(start_date='2000-01-01', end_date='2021-12-31'):

[{'customer_id': 8675309,
 'date_entered': '2000-01-01T00:00:00.0000000-06:00',
 'purchase_order': 'TEST',
 'salesorder_id': 58223023}, {'customer_id': 8675309,
 'date_entered': '2021-12-31T00:00:00.0000000-06:00',
 'purchase_order': 'PO123',
 'salesorder_id': 58150868}]

If I then use one of the salesorder_id to query the details of that order using digikey.status_salesorder_id(sales_order_id=58223023), I only get None as a result.

Did anyone manage to make this work? Is there any example about listing the positions of a sales order?

Thanks!

First use with the api

Hello Peeter123, I am new in coding and doing a new program on digikey.com but I met lots problems.

I want to use your api but I dont know how to start. For example keywords search to find quantity available of products.

Can you show me with a simple code example? Thank you a lot!

Allow for variables to be fed in instead of using OS environment variables

As the title says, this library should allow for some information like client-id to be fed into it with the user application instead of using environment variables. Then these variables can be stored in the library's configuration file. The configuration file as well should be given to the library as an argument instead of using an environment variable.

Query responce incorrect

Has anyone gotten this to work recently? I'm querying for CL10A106MQ8NNNC. However, the output is for something completely different. Any help would be appreciated.

[machinehum@whitebox digi-api]$ cat main.sh 
export DIGIKEY_CLIENT_ID="<My client ID>"
export DIGIKEY_CLIENT_SECRET="<My Key>"
export DIGIKEY_CLIENT_SANDBOX="True"
export DIGIKEY_STORAGE_PATH="cache_dir"
mkdir $DIGIKEY_STORAGE_PATH 2>/dev/null

# python -i generate_bom.py
python -i digi_api.py
[machinehum@whitebox digi-api]$ cat digi_api.py 
import os
import digikey
from digikey.v3.productinformation import KeywordSearchRequest

# Query product number
# dkpn = '296-6501-1-ND'
# part = digikey.product_details(dkpn)

# os.environ['DIGIKEY_CLIENT_ID'] = 'client_id'
# os.environ['DIGIKEY_CLIENT_SECRET'] = 'client_secret'
# os.environ['DIGIKEY_CLIENT_SANDBOX'] = 'False'
# os.environ['DIGIKEY_STORAGE_PATH'] = 'cache_dir'

# Search for parts
search_request = KeywordSearchRequest(keywords='CL10A106MQ8NNNC', record_count=10)
result = digikey.keyword_search(body=search_request)

print(result)
[machinehum@whitebox digi-api]$ ./main.sh 
{'exact_digi_key_product': None,
 'exact_manufacturer_products': [],
 'exact_manufacturer_products_count': 0,
 'filter_options': [{'parameter': 'Manufacturer',
                     'parameter_id': -1,
                     'values': [{'value': 'Panasonic Electronic Components',
                                 'value_id': '10'}]},
                    {'parameter': 'Packaging',
                     'parameter_id': 7,
                     'values': [{'value': 'Bulk', 'value_id': '3'}]},
                    {'parameter': 'Series',
                     'parameter_id': -5,
                     'values': [{'value': 'NHG', 'value_id': '189'}]},
                    {'parameter': 'Part Status',
                     'parameter_id': 1989,
                     'values': [{'value': 'Active', 'value_id': '0'}]},
                    {'parameter': 'Capacitance',
                     'parameter_id': 13,
                     'values': [{'value': '1000µF', 'value_id': '65'}]},
                    {'parameter': 'Tolerance',
                     'parameter_id': 3,
                     'values': [{'value': '±20%', 'value_id': '5'}]},
                    {'parameter': 'Voltage Rating',
                     'parameter_id': 63,
                     'values': [{'value': '35V', 'value_id': '371'}]},
                    {'parameter': 'ESR (Equivalent Series Resistance)',
                     'parameter_id': 724,
                     'values': [{'value': '-', 'value_id': '233'}]},
                    {'parameter': 'Lifetime @ Temp.',
                     'parameter_id': 725,
                     'values': [{'value': '2000 Hrs @ 105°C',
                                 'value_id': '7'}]},
                    {'parameter': 'Operating Temperature',
                     'parameter_id': 252,
                     'values': [{'value': '-55°C ~ 105°C', 'value_id': '42'}]},
                    {'parameter': 'Polarization',
                     'parameter_id': 52,
                     'values': [{'value': 'Polar', 'value_id': '14'}]},
                    {'parameter': 'Applications',
                     'parameter_id': 405,
                     'values': [{'value': 'General Purpose',
                                 'value_id': '19'}]},
                    {'parameter': 'Ripple Current',
                     'parameter_id': 1317,
                     'values': [{'value': '810mA @ 120Hz',
                                 'value_id': '3670'}]},
                    {'parameter': 'Impedance',
                     'parameter_id': 60,
                     'values': [{'value': '-', 'value_id': '89'}]},
                    {'parameter': 'Lead Spacing',
                     'parameter_id': 508,
                     'values': [{'value': '0.197" (5.00mm)', 'value_id': '4'}]},
                    {'parameter': 'Size / Dimension',
                     'parameter_id': 46,
                     'values': [{'value': '0.492" Dia (12.50mm)',
                                 'value_id': '13984'}]},
                    {'parameter': 'Height - Seated (Max)',
                     'parameter_id': 1500,
                     'values': [{'value': '0.866" (22.00mm)',
                                 'value_id': '273'}]},
                    {'parameter': 'Surface Mount Land Size',
                     'parameter_id': 884,
                     'values': [{'value': '-', 'value_id': '4'}]},
                    {'parameter': 'Mounting Type',
                     'parameter_id': 69,
                     'values': [{'value': 'Through Hole', 'value_id': '80'}]},
                    {'parameter': 'Package / Case',
                     'parameter_id': 16,
                     'values': [{'value': 'Radial, Can',
                                 'value_id': '11811'}]}],
 'limited_taxonomy': {'children': [{'children': [{'children': [],
                                                  'new_product_count': 0,
                                                  'parameter': 'Categories',
                                                  'parameter_id': -8,
                                                  'product_count': 1,
                                                  'value': 'Aluminum '
                                                           'Capacitors',
                                                  'value_id': '58'}],
                                    'new_product_count': 0,
                                    'parameter': 'Categories',
                                    'parameter_id': -8,
                                    'product_count': 1,
                                    'value': 'Capacitors',
                                    'value_id': '3'}],
                      'new_product_count': 0,
                      'parameter': 'Categories',
                      'parameter_id': -8,
                      'product_count': 1,
                      'value': 'Out of Bounds',
                      'value_id': '0'},
 'products': [{'alternate_packaging': [],
               'category': None,
               'date_last_buy_chance': None,
               'detailed_description': None,
               'digi_key_part_number': 'P5555-ND',
               'dk_plus_restriction': False,
               'export_control_class_number': None,
               'family': None,
               'htsus_code': None,
               'lead_status': 'Lead Free',
               'manufacturer': {'parameter': '',
                                'parameter_id': 0,
                                'value': 'Panasonic Electronic Components',
                                'value_id': '10'},
               'manufacturer_lead_weeks': '14 weeks',
               'manufacturer_page_url': 'https://www.digikey.com/en/supplier-centers/p/panasonic',
               'manufacturer_part_number': 'ECA-1VHG102',
               'manufacturer_public_quantity': 0,
               'marketplace': False,
               'minimum_order_quantity': 1,
               'moisture_sensitivity_level': '',
               'non_stock': False,
               'packaging': {'parameter': 'Packaging',
                             'parameter_id': 7,
                             'value': 'Bulk',
                             'value_id': '3'},
               'parameters': [{'parameter': 'Packaging',
                               'parameter_id': 7,
                               'value': 'Bulk',
                               'value_id': '3'},
                              {'parameter': 'Part Status',
                               'parameter_id': 1989,
                               'value': 'Active',
                               'value_id': '0'},
                              {'parameter': 'Capacitance',
                               'parameter_id': 13,
                               'value': '1000µF',
                               'value_id': '65'},
                              {'parameter': 'Tolerance',
                               'parameter_id': 3,
                               'value': '±20%',
                               'value_id': '5'},
                              {'parameter': 'Voltage Rating',
                               'parameter_id': 63,
                               'value': '35V',
                               'value_id': '371'},
                              {'parameter': 'ESR (Equivalent Series '
                                            'Resistance)',
                               'parameter_id': 724,
                               'value': '-',
                               'value_id': '233'},
                              {'parameter': 'Lifetime @ Temp.',
                               'parameter_id': 725,
                               'value': '2000 Hrs @ 105°C',
                               'value_id': '7'},
                              {'parameter': 'Operating Temperature',
                               'parameter_id': 252,
                               'value': '-55°C ~ 105°C',
                               'value_id': '42'},
                              {'parameter': 'Polarization',
                               'parameter_id': 52,
                               'value': 'Polar',
                               'value_id': '14'},
                              {'parameter': 'Applications',
                               'parameter_id': 405,
                               'value': 'General Purpose',
                               'value_id': '19'},
                              {'parameter': 'Ripple Current',
                               'parameter_id': 1317,
                               'value': '810mA @ 120Hz',
                               'value_id': '3670'},
                              {'parameter': 'Impedance',
                               'parameter_id': 60,
                               'value': '-',
                               'value_id': '89'},
                              {'parameter': 'Lead Spacing',
                               'parameter_id': 508,
                               'value': '0.197" (5.00mm)',
                               'value_id': '4'},
                              {'parameter': 'Size / Dimension',
                               'parameter_id': 46,
                               'value': '0.492" Dia (12.50mm)',
                               'value_id': '13984'},
                              {'parameter': 'Height - Seated (Max)',
                               'parameter_id': 1500,
                               'value': '0.866" (22.00mm)',
                               'value_id': '273'},
                              {'parameter': 'Surface Mount Land Size',
                               'parameter_id': 884,
                               'value': '-',
                               'value_id': '4'},
                              {'parameter': 'Mounting Type',
                               'parameter_id': 69,
                               'value': 'Through Hole',
                               'value_id': '80'},
                              {'parameter': 'Package / Case',
                               'parameter_id': 16,
                               'value': 'Radial, Can',
                               'value_id': '11811'}],
               'primary_datasheet': 'https://industrial.panasonic.com/cdbs/www-data/pdf/RDF0000/ABA0000C1215.pdf',
               'primary_photo': 'http://media.digikey.com/Photos/Panasonic%20Photos/NHG12-SERIES.jpg',
               'primary_video': '',
               'product_description': 'CAP ALUM 1000UF 20% 35V RADIAL',
               'product_status': 'Active',
               'product_url': '/product-detail/en/panasonic-electronic-components/ECA-1VHG102/P5555-ND/245154',
               'quantity_available': 8888,
               'quantity_on_order': 0,
               'reach_status': None,
               'ro_hs_status': 'RoHS Compliant',
               'series': {'parameter': 'Series',
                          'parameter_id': -5,
                          'value': 'NHG',
                          'value_id': '189'},
               'standard_pricing': [{'break_quantity': 1,
                                     'total_price': 0.78,
                                     'unit_price': 0.78},
                                    {'break_quantity': 10,
                                     'total_price': 5.93,
                                     'unit_price': 0.593},
                                    {'break_quantity': 25,
                                     'total_price': 13.12,
                                     'unit_price': 0.5248},
                                    {'break_quantity': 50,
                                     'total_price': 24.64,
                                     'unit_price': 0.4928},
                                    {'break_quantity': 100,
                                     'total_price': 42.43,
                                     'unit_price': 0.4243},
                                    {'break_quantity': 250,
                                     'total_price': 95.81,
                                     'unit_price': 0.38324},
                                    {'break_quantity': 500,
                                     'total_price': 164.25,
                                     'unit_price': 0.3285},
                                    {'break_quantity': 1000,
                                     'total_price': 282.88,
                                     'unit_price': 0.28288},
                                    {'break_quantity': 5000,
                                     'total_price': 1254.7,
                                     'unit_price': 0.25094}],
               'supplier_direct_ship': False,
               'tariff_description': None,
               'unit_price': 78000.0}],
 'products_count': 1,
 'search_locale_used': {'currency': 'USD',
                        'language': 'en',
                        'ship_to_country': '',
                        'site': 'US'}}

headless use

Hi,

I want to use this module on a headless server, so getting the OAUTH token via a login in a browser isn't a viable option. Is there another way to get the token?

Greetings,
Tojan

Setting Environment Variables on Windows

I set up the variables are directed but I get the error: 'ValueError: CLIENT ID and SECRET must be set. Set 'DIGIKEY_CLIENT_ID' and 'DIGIKEY_CLIENT_SECRET' as an environment variable, or pass your keys directly to the client.'

How do I call the client and set it up directly? Or better still how can I properly set up the variables and call os.environ? Note: I didn't work so I used os.geten, didn't work still.

Thanks for the help!

401 error on batch_product_details

I'm attempting to use the batch product details API like this (is there documentation on how you are supposed to do this? I'm basing it off the keyword_search example):

from digikey.v3.batchproductdetails import BatchProductDetailsRequest

...

batch_request = BatchProductDetailsRequest(products=['MMSZ5231B-FDICT-ND', 'BZX84C5V6-FDICT-ND'])
parts = digikey.batch_product_details(body=batch_request)

This results in the following error:

ApiException: (401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({'Date': 'Fri, 03 Feb 2023 19:35:18 GMT', 'Content-Type': 'application/json', 'Content-Length': '228', 'Connection': 'keep-alive', 'Access-Control-Allow-Origin': '', 'Access-Control-Allow-Headers': 'origin, x-requested-with, accept, content-type, authorization,x-digikey-client-id, x-digikey-locale-site, x-digikey-locale-language, x-digikey-locale-currency, x-digikey-locale-shiptocountry, x-digikey-customer-id', 'Access-Control-Max-Age': '3628800', 'Access-Control-Allow-Methods': 'POST', 'X-DIGIKEY-REQUEST-ID': '5d4263b6-648e-4996-811e-f03373f8d46d', 'Set-Cookie': '[hiding cookie string for security]; Path=/; Secure; HTTPOnly'})
HTTP response body: {"ErrorResponseVersion":"3.0.0.0","StatusCode": 401,"ErrorMessage":"Invalid Client-Id","ErrorDetails":"X-DIGIKEY-Client-Id invalid for requested resource","RequestId":"5d4263b6-648e-4996-811e-f03373f8d46d","ValidationErrors":[]}

I can successfully use keyword_search and product_details so it seems like my client ID must be correct. Is there some other API permissions I need to enable on my digikey account?

Edit: Perhaps this is related? https://forum.digikey.com/t/x-digikey-client-id-invalid-for-requested-resource/26675

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.