digikey-api icon indicating copy to clipboard operation
digikey-api copied to clipboard

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

Open clementspeter opened this issue 4 years ago • 18 comments

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

clementspeter avatar Dec 14 '20 10:12 clementspeter

@clementspeter to convert to dictionary you can use the following method:

digikey.product_details(part).to_dict()

With part being the part number.

eeintech avatar Dec 14 '20 17:12 eeintech

Dear Francois, Thank you for your answer - I'll try this out.

Have you succeeded in getting the manufacturer_product_details function to work? Are you able to reproduce the error message? Looking forward understanding what I did wrong.

clementspeter avatar Dec 14 '20 20:12 clementspeter

@clementspeter No I haven't tried that function, I'm getting all data I need with the product_details method

eeintech avatar Dec 14 '20 21:12 eeintech

@eeintech thanks, do all 3 functions (search / product details and manufacturer_product_details) provide the same output? What would be the interest?

I just tried the dict command and it works, thanks for the hint!

clementspeter avatar Dec 14 '20 21:12 clementspeter

To phrase it differently: when should which function ideally be used / provides the most accurate or complete results?

clementspeter avatar Dec 14 '20 22:12 clementspeter

This was a simple bug. I fixed it in my fork (https://github.com/Funkenjaeger/digikey-api)

Regarding the difference between the three functions, I suggest referring to the DigiKey API definitions, which this library is just faithfully interfacing. At a glance I believe that the distinctions are, from most specific to most generic:

  • product_details() returns product details for a specific digikey part number (can also use a manufacturer part number, but be aware that it only returns one result even if there are multiple matches, so you may get the wrong part)
  • manufacturer_product_details() returns search results for a manufacturer part number
  • keyword_search() does 'Search by keyword, then narrow down the search using available filters and search options.'

Funkenjaeger avatar Dec 14 '20 23:12 Funkenjaeger

@Funkenjaeger product_details() also works with manufacturer part numbers 😉

eeintech avatar Dec 15 '20 12:12 eeintech

@eeintech True, sometimes it does. The actual argument passed to the digikey API is named "digiKeyPartNumber", and the summary in the API description states "Works best with a Digi-Key part number. Some manufacturer part numbers conflict with unrelated parts and may not return the correct product."

I've updated my above comment to reflect that technically, using MPN is possible, but at your own risk. An example of where that would bite you would be the part 36-2090-ND (MPN is '2090'), which is a hex standoff. product_details() using the MPN returns an Adafruit LCD display, while manufacturer_product_details() returns a list containing both parts.

Funkenjaeger avatar Dec 15 '20 12:12 Funkenjaeger

Oh that's interesting. For Ki-nTree my colleagues and I have been solely relying on product_details() and never ran into this issue. I might look closer into manufacturer_product_details() after your PR is approved and merged.

eeintech avatar Dec 15 '20 14:12 eeintech

Hello,

I do have the same king of error with the following part number: DMT3N4R2U224M3DTA0 Here is what I do:

jsom_bom = digikey.product_details(str(manf)).to_dict()
outputfile = './json/product_details_'+str(manf)+'.json'
with open(outputfile, 'w') as outfile:
        json.dump(jsom_bom, outfile)

The error is the following: TypeError: Object of type datetime is not JSON serializable Note that I added .to_dict() as specified in the post up here..

sebo83910 avatar Jul 12 '21 13:07 sebo83910

@sebo83910 Assuming you did manf = 'DMT3N4R2U224M3DTA0' and import json this code works (I tested it with Python 3.8 and latest release from this repo). You may have an issue somewhere else in your code.

eeintech avatar Jul 12 '21 14:07 eeintech

This is strange:

$ python ./pydigikey.py
2021-07-12 16:26:54,220 - digikey.oauth.oauth2 -    DEBUG: Using API V3
2021-07-12 16:26:54,220 -       digikey.v3.api -     INFO: Get product details for: DMT3N4R2U224M3DTA0
2021-07-12 16:26:54,220 -       digikey.v3.api -    DEBUG: CALL wrapped -> PartSearchApi.product_details_with_http_info
2021-07-12 16:26:55,085 -       digikey.v3.api -    DEBUG: Requests remaining: [941/1000]
Traceback (most recent call last):
  File "./pydigikey.py", line 84, in <module>
    json.dump(jsom_bom, outfile)
  File "/usr/lib/python3.8/json/__init__.py", line 179, in dump
    for chunk in iterable:
  File "/usr/lib/python3.8/json/encoder.py", line 431, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/lib/python3.8/json/encoder.py", line 438, in _iterencode
    o = _default(o)
  File "/usr/lib/python3.8/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type datetime is not JSON serializable

$ python --version
Python 3.8.10

$ pip show digikey-api
Name: digikey-api
Version: 0.4.0
Summary: Python client for Digikey API
Home-page: https://github.com/peeter123/digikey-api
Author: Peter Oostewechel
Author-email: [email protected]
License: GPL v3
Location: /usr/local/lib/python3.8/site-packages
Requires: urllib3, inflection, schematics, retrying, requests, certauth, fake-useragent
Required-by:

sebo83910 avatar Jul 12 '21 14:07 sebo83910

What do you get in your jsom_bom dict?

I have:

{'my_pricing': [], 'obsolete': True, 'media_links': [{'media_type': 'Datasheets                                                                                                                     ', 'title': 'DMF/DMT Series Part Numbering', 'small_photo': '', 'thumbnail': '', 'url': 'https://www.murata.com/en-eu/products/productdata/8796857532446/L1140E.pdf'}, {'media_type': 'Datasheets                                                                                                                     ', 'title': 'DMT3N4R2U224M3DTA0', 'small_photo': '', 'thumbnail': '', 'url': 'https://www.murata.com/~/media/webrenewal/products/capacitor/edlc/feature/edlc%20dmt220mf_datasheet.ashx?la=en'}, {'media_type': 'Featured Product                                                                                                               ', 'title': '220 mF Model of the Supercapacitor DMT Series', 'small_photo': '', 'thumbnail': '', 'url': 'https://www.digikey.com/en/product-highlight/m/murata-electronics-north-america/220-mf-model-supercapacitor'}, {'media_type': 'Product Photos                                                                                                                 ', 'title': 'DMT3N4R2U224M3DTA0', 'small_photo': 'http://media.digikey.com/Photos/Murata%20Photos/MFG_DMT3N4R2U224M3DTA0_sml.jpg', 'thumbnail': 'http://media.digikey.com/Photos/Murata%20Photos/MFG_DMT3N4R2U224M3DTA0_tmb.jpg', 'url': 'http://media.digikey.com/Photos/Murata%20Photos/MFG_DMT3N4R2U224M3DTA0.jpg'}, {'media_type': 'Video File                                                                                                                     ', 'title': "Murata's 220 mF Supercapacitor DMT Series | Digi-Key Daily", 'small_photo': '', 'thumbnail': '', 'url': 'https://www.digikey.com/api/videos/videoplayer/smallplayer/4791966245001'}, {'media_type': 'PCN Obsolescence/ EOL', 'title': 'DM,UMA Series 28/Sep/2018', 'small_photo': '', 'thumbnail': '', 'url': 'http://media.digikey.com/pdf/PCNs/Murata/C2M1CXS-515.pdf'}, {'media_type': 'HTML Datasheet', 'title': 'DMF/DMT Series Part Numbering', 'small_photo': '', 'thumbnail': '', 'url': 'https://www.digikey.com/htmldatasheets/production/1794476/0/0/1/dmf-dmt-series-part-numbering.html'}, {'media_type': 'HTML Datasheet', 'title': 'DMT3N4R2U224M3DTA0', 'small_photo': '', 'thumbnail': '', 'url': 'https://www.digikey.com/htmldatasheets/production/1864219/0/0/1/dmt3n4r2u224m3dta0.html'}, {'media_type': 'EDA / CAD Models', 'title': 'DMT3N4R2U224M3DTA0 by Ultra Librarian', 'small_photo': '', 'thumbnail': '', 'url': 'https://app.ultralibrarian.com/details/A54A0AA4-091C-11EB-9033-0A34D6323D74/Murata/DMT3N4R2U224M3DTA0?ref=digikey'}], 'standard_package': 50, 'limited_taxonomy': {'children': [{'children': [{'children': [], 'product_count': 1, 'new_product_count': 0, 'parameter_id': -8, 'value_id': '61', 'parameter': 'Categories', 'value': 'Electric Double Layer Capacitors (EDLC), Supercapacitors'}], 'product_count': 1, 'new_product_count': 0, 'parameter_id': -8, 'value_id': '3', 'parameter': 'Categories', 'value': 'Capacitors'}], 'product_count': 1, 'new_product_count': 0, 'parameter_id': -8, 'value_id': '0', 'parameter': 'Categories', 'value': 'Out of Bounds'}, 'kits': [], 'kit_contents': [], 'mating_products': [], 'search_locale_used': {'site': 'US', 'language': 'en', 'currency': 'USD', 'ship_to_country': 'US'}, 'associated_products': [], 'for_use_with_products': [], 'rohs_subs': [], 'suggested_subs': [], 'additional_value_fee': 0.0, 'reach_effective_date': '', 'standard_pricing': [], 'ro_hs_status': 'Request Inventory Verification', 'lead_status': 'Lead Free', 'parameters': [{'parameter_id': -1, 'value_id': '490', 'parameter': 'Manufacturer', 'value': 'Murata Electronics'}, {'parameter_id': 7, 'value_id': '17', 'parameter': 'Packaging', 'value': 'Tray'}, {'parameter_id': 1989, 'value_id': '1', 'parameter': 'Part Status', 'value': 'Obsolete'}, {'parameter_id': 2049, 'value_id': 'u220mF', 'parameter': 'Capacitance', 'value': '220mF'}, {'parameter_id': 3, 'value_id': '1900', 'parameter': 'Tolerance', 'value': '±20%'}, {'parameter_id': 2079, 'value_id': 'u4.2V', 'parameter': 'Voltage - Rated', 'value': '4.2V'}, {'parameter_id': 724, 'value_id': '182444', 'parameter': 'ESR (Equivalent Series Resistance)', 'value': '300mOhm'}, {'parameter_id': 725, 'value_id': '68154', 'parameter': 'Lifetime @ Temp.', 'value': '1000 Hrs @ 85°C'}, {'parameter_id': 589, 'value_id': '404186', 'parameter': 'Termination', 'value': 'SMD (SMT) Tabs'}, {'parameter_id': 69, 'value_id': '409393', 'parameter': 'Mounting Type', 'value': 'Surface Mount'}, {'parameter_id': 16, 'value_id': '202559', 'parameter': 'Package / Case', 'value': '3-SMD, Gull Wing'}, {'parameter_id': 508, 'value_id': '1', 'parameter': 'Lead Spacing', 'value': '-'}, {'parameter_id': 46, 'value_id': '35013', 'parameter': 'Size / Dimension', 'value': '0.827" L x 0.551" W (21.00mm x 14.00mm)'}, {'parameter_id': 1500, 'value_id': '8933', 'parameter': 'Height - Seated (Max)', 'value': '0.087" (2.20mm)'}, {'parameter_id': 252, 'value_id': '212617', 'parameter': 'Operating Temperature', 'value': '-40°C ~ 85°C'}, {'parameter_id': 2078, 'value_id': '178529', 'parameter': 'Base Part Number', 'value': 'DMT3N4R2U'}], 'product_url': 'https://www.digikey.com/product-detail/en/murata-electronics/DMT3N4R2U224M3DTA0/490-13208-ND/5824504', 'primary_datasheet': 'https://www.murata.com/~/media/webrenewal/products/capacitor/edlc/feature/edlc%20dmt220mf_datasheet.ashx?la=en', 'primary_photo': 'https://media.digikey.com/Photos/Murata%20Photos/MFG_DMT3N4R2U224M3DTA0.jpg', 'primary_video': 'https://www.digikey.com/api/videos/videoplayer/smallplayer/4791966245001', 'series': {'parameter_id': -5, 'value_id': '10923', 'parameter': 'Series', 'value': 'DMT'}, 'manufacturer_lead_weeks': '', 'manufacturer_page_url': 'https://www.digikey.com/en/supplier-centers/murata-electronics', 'product_status': 'Obsolete', 'date_last_buy_chance': '2019-03-29T01:00:00-05:00', 'alternate_packaging': [], 'detailed_description': '220mF (EDLC) Supercapacitor 4.2V 3-SMD, Gull Wing 300mOhm 1000 Hrs @ 85°C', 'reach_status': 'Reach unknown', 'export_control_class_number': 'EAR99', 'htsus_code': '8532.29.0040', 'tariff_description': '', 'manufacturer_part_number': 'DMT3N4R2U224M3DTA0', 'minimum_order_quantity': 1, 'non_stock': True, 'packaging': {'parameter_id': 7, 'value_id': '17', 'parameter': 'Packaging', 'value': 'Tray'}, 'quantity_available': 0, 'digi_key_part_number': '490-13208-ND', 'product_description': 'CAP 220MF 20% 4.2V SMD', 'unit_price': 0.0, 'manufacturer': {'parameter_id': -9, 'value_id': '490', 'parameter': 'Manufacturer', 'value': 'Murata Electronics'}, 'manufacturer_public_quantity': 0, 'quantity_on_order': 0, 'dk_plus_restriction': False, 'supplier_direct_ship': False}

eeintech avatar Jul 12 '21 14:07 eeintech

Also there are plenty of discussion about this error on Google, take a look!

eeintech avatar Jul 12 '21 14:07 eeintech

Also there are plenty of discussion about this error on Google, take a look!

indeed, I solved it like this:

with open(outputfile, 'w') as outfile:
        json.dump(jsom_bom.__str__(), outfile)

Thanks for your help.

sebo83910 avatar Jul 12 '21 15:07 sebo83910

@clementspeter Any chance you can close this issue?

eeintech avatar Jul 21 '21 14:07 eeintech

Hi,

I need to have a look – am pretty occupied for the next 2 weeks with some other projects, but I schedule it in!

From: Francois @.*** Sent: 21 July 2021 16:38 To: peeter123/digikey-api @.> Cc: clementspeter @.>; Mention @.***> Subject: Re: [peeter123/digikey-api] AttributeError: 'ManufacturerProductDetailsRequest' object has no attribute 'keywords' (#8)

@clementspeter https://github.com/clementspeter Any chance you can close this issue?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/peeter123/digikey-api/issues/8#issuecomment-884242036 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ASDWEHEQMJY76IMRR6X763TTY3LTPANCNFSM4U2R67NA .

clementspeter avatar Jul 23 '21 08:07 clementspeter

@clementspeter No problem, it's a real issue unfortunately. Hoping some activity from @peeter123 to take a look at current PR before proposing a fix.

eeintech avatar Jul 23 '21 15:07 eeintech