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'
Fixed, I think my SSL library installed with python was corrupt, I set up a virtual environment inside WSL and copied the SSL library code from there and pasted it into my main window system's SSL 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:
Error:
Any help would be appreciated,
Thanks very much,
Ben