sparkmicro / Ki-nTree

Fast part creation for KiCad and InvenTree
GNU General Public License v3.0
171 stars 31 forks source link

LCSC parts creation issues #234

Closed NightSkySK closed 2 weeks ago

NightSkySK commented 1 month ago

I found that some parts from LCSC doesn't have parameters paramVOList which crashing Ki-nTree:

[MAIN]  LCSC search for C2997275
Future exception was never retrieved
future: <Future finished exception=KeyError('paramVOList')>
Traceback (most recent call last):
  File "C:\Python\Python311\Lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\KSM\kintree\env\Lib\site-packages\flet_core\page.py", line 528, in wrapper
    handler(*args)
  File "C:\KSM\kintree\env\Lib\site-packages\kintree\gui\views\main.py", line 330, in run_search
    part_supplier_info = inventree_interface.supplier_search(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\KSM\kintree\env\Lib\site-packages\kintree\database\inventree_interface.py", line 480, in supplier_search
    part_info = lcsc_api.fetch_part_info(part_number)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\KSM\kintree\env\Lib\site-packages\kintree\search\lcsc_api.py", line 99, in fetch_part_info
    for parameter in range(len(part[parameter_key])):
                               ~~~~^^^^^^^^^^^^^^^
KeyError: 'paramVOList'

API return

JSON response ```JSON { "code": 200, "msg": null, "result": { "currencyType": "USD", "isAutoOffsale": false, "productArrange": "Bag-packed", "productModel": "DB302-5.0-2P-GN-S", "reelPrice": 0, "stockNumber": 12525, "productIntroEn": " P=5mm Screw terminal ROHS", "productUnit": "Piece", "isReel": false, "parentCatalogName": "Connectors", "title": "DORABO DB302-5.0-2P-GN-S", "isHasBattery": false, "overseasStockVO": { "total": 12525, "ship3Days": 4925, "shipImmediately": 7600 }, "pdfUrl": "https://datasheet.lcsc.com/lcsc/2301061609_DORABO-DB302-5-0-2P-GN-S_C2997275.pdf", "wmStockHk": 0, "catalogId": 11140, "split": 5, "stockJs": 4925, "domesticStockVO": { "total": 12525, "ship3Days": 4925, "shipImmediately": 7600 }, "productPriceList": [ { "currencyPrice": 0.2077, "discountRate": "0.80", "ladder": 5, "usdPrice": 0.2077, "currencySymbol": "$", "productPrice": "0.2077" }, { "currencyPrice": 0.1695, "discountRate": "0.80", "ladder": 50, "usdPrice": 0.1695, "currencySymbol": "$", "productPrice": "0.1695" }, { "currencyPrice": 0.1531, "discountRate": "0.80", "ladder": 150, "usdPrice": 0.1531, "currencySymbol": "$", "productPrice": "0.1531" }, { "currencyPrice": 0.1235, "discountRate": "0.80", "ladder": 500, "usdPrice": 0.1235, "currencySymbol": "$", "productPrice": "0.1235" }, { "currencyPrice": 0.1144, "discountRate": "0.80", "ladder": 2500, "usdPrice": 0.1144, "currencySymbol": "$", "productPrice": "0.1144" }, { "currencyPrice": 0.109, "discountRate": "0.80", "ladder": 5000, "usdPrice": 0.109, "currencySymbol": "$", "productPrice": "0.1090" } ], "isEnvironment": true, "minPacketUnit": "Bag", "minBuyNumber": 5, "productId": 3468088, "eccn": "-", "isForeignOnsale": true, "minPacketNumber": 500, "currencySymbol": "$", "weight": 2.4, "isPreSale": false, "productWeight": 0.0024, "catalogName": "Screw terminal", "productImages": [ "https://assets.lcsc.com/images/lcsc/900x900/20230106_DORABO-DB302-5-0-2P-GN-S_C2997275_front.jpg", "https://assets.lcsc.com/images/lcsc/900x900/20230106_DORABO-DB302-5-0-2P-GN-S_C2997275_back.jpg", "https://assets.lcsc.com/images/lcsc/900x900/20230106_DORABO-DB302-5-0-2P-GN-S_C2997275_blank.jpg" ], "productCode": "C2997275", "stockSz": 7600, "encapStandard": "P=5mm", "parentCatalogId": 365, "brandId": 11964, "brandNameEn": "DORABO", "ladderDiscountRate": "1~0.80,10~0.80,30~0.80,100~0.80,500~0.80,1000~0.80,", "maxBuyNumber": -1, "isHot": false } } ```

Another connector even if has paramVOList also causing problems with part creation:

[MAIN]  Using LCSC cached data for C2916457
[TREE]  Successfully connected to InvenTree server (ENV=DEVELOPMENT)
[INFO]  Warning: The following parameters were not found in supplier data:
['Frequency - Max', 'Locking Feature', 'Fastening Type', 'Locking system', 'Mated Stacking Heights', 'Mounting Type', 'Electrical mounting', 'Number of Contacts', 'Number of Positions', 'Number of pins', 'Number of Rows', 'Connector pinout layout', 'Orientation', 'Spatial orientation', 'Height Above Board', 'Insulation Height', 'Height', 'Pitch', 'Pitch - Mating', 'Contacts pitch', 'Gender', 'Kind of connector', 'Current rating', 'Rated voltage', 'Operating Temperature', 'Operating temperature']
[INFO]  The following parameters are not mapped in LCSC parameters configuration:
['Contact Material', 'Contact Plating', 'LED', 'Mounting Style', 'Number of Ports', 'Operating Temperature Range', 'Soldering Temperature(Max)']
[TREE]  Error: Part creation failed. Check if Ki-nTree settings match InvenTree part settings.

[MAIN]  Downloading Datasheet
[INFO]  Warning: PDF download returned the wrong file type
[INFO]  Warning: PDF download returned the wrong file type
[INFO]  Warning: PDF download returned the wrong file type

API return

JSON response ```json { "code": 200, "msg": null, "result": { "currencyType": "USD", "isAutoOffsale": false, "productArrange": "Tray", "productModel": "X31ADIWA3DY1027", "reelPrice": 0, "stockNumber": 940, "productIntroEn": "RJ45Receptacle Unshielded 1 Right-Angle 260℃ Gold Phosphor bronze Without LED -40℃~+85℃ Plugin Ethernet Connectors/Modular Connectors (RJ45 RJ11) ROHS", "productUnit": "Piece", "isReel": false, "parentCatalogName": "Connectors", "title": "XKB Connection X31ADIWA3DY1027", "isHasBattery": false, "overseasStockVO": { "total": 940, "ship3Days": 930, "shipImmediately": 10 }, "pdfUrl": "https://datasheet.lcsc.com/lcsc/2111251530_XKB-Connection-X31ADIWA3DY1027_C2916457.pdf", "wmStockHk": 0, "catalogId": 449, "split": 5, "stockJs": 930, "domesticStockVO": { "total": 940, "ship3Days": 930, "shipImmediately": 10 }, "productPriceList": [ { "currencyPrice": 0.2753, "discountRate": "1", "ladder": 5, "usdPrice": 0.2753, "currencySymbol": "$", "productPrice": "0.2753" }, { "currencyPrice": 0.2268, "discountRate": "1", "ladder": 50, "usdPrice": 0.2268, "currencySymbol": "$", "productPrice": "0.2268" }, { "currencyPrice": 0.1902, "discountRate": "1", "ladder": 200, "usdPrice": 0.1902, "currencySymbol": "$", "productPrice": "0.1902" }, { "currencyPrice": 0.1643, "discountRate": "1", "ladder": 500, "usdPrice": 0.1643, "currencySymbol": "$", "productPrice": "0.1643" }, { "currencyPrice": 0.1527, "discountRate": "1", "ladder": 2500, "usdPrice": 0.1527, "currencySymbol": "$", "productPrice": "0.1527" }, { "currencyPrice": 0.1458, "discountRate": "1", "ladder": 5000, "usdPrice": 0.1458, "currencySymbol": "$", "productPrice": "0.1458" } ], "isEnvironment": true, "minPacketUnit": "Tray", "minBuyNumber": 5, "productId": 3212366, "eccn": "-", "isForeignOnsale": true, "minPacketNumber": 100, "currencySymbol": "$", "weight": 3.5, "isPreSale": false, "productWeight": 0.0035, "catalogName": "Ethernet Connectors/Modular Connectors (RJ45 RJ11)", "productImages": [ "https://assets.lcsc.com/images/lcsc/900x900/20230121_XKB-Connection-X31ADIWA3DY1027_C2916457_front.jpg", "https://assets.lcsc.com/images/lcsc/900x900/20230121_XKB-Connection-X31ADIWA3DY1027_C2916457_back.jpg", "https://assets.lcsc.com/images/lcsc/900x900/20230121_XKB-Connection-X31ADIWA3DY1027_C2916457_blank.jpg" ], "productCode": "C2916457", "stockSz": 10, "encapStandard": "Plugin", "paramVOList": [ { "paramValueEnForSearch": -1, "paramValueEn": "RJ45Receptacle", "paramCode": "param_13471", "isMain": true, "sortNumber": 1, "paramNameEn": "Connector Type", "paramName": "连接器类型", "paramValue": "RJ45插座" }, { "paramValueEnForSearch": -1, "paramValueEn": "Unshielded", "paramCode": "param_13476", "isMain": true, "sortNumber": 1, "paramNameEn": "Shielding", "paramName": "屏蔽", "paramValue": "无屏蔽" }, { "paramValueEnForSearch": 1, "paramValueEn": "1", "paramCode": "param_13473_n", "isMain": true, "sortNumber": 1, "paramNameEn": "Number of Ports", "paramName": "端口数量", "paramValue": "1" }, { "paramValueEnForSearch": -1, "paramValueEn": "Right-Angle", "paramCode": "param_13475", "isMain": true, "sortNumber": 1, "paramNameEn": "Mounting Style", "paramName": "安装方式", "paramValue": "弯插" }, { "paramValueEnForSearch": 260, "paramValueEn": "260℃", "paramCode": "param_13481_nt", "isMain": true, "sortNumber": 1, "paramNameEn": "Soldering Temperature(Max)", "paramName": "焊接温度(最大值)", "paramValue": "260℃" }, { "paramValueEnForSearch": -1, "paramValueEn": "Gold", "paramCode": "param_13479", "isMain": true, "sortNumber": 1, "paramNameEn": "Contact Plating", "paramName": "触头镀层", "paramValue": "金" }, { "paramValueEnForSearch": -1, "paramValueEn": "Phosphor bronze", "paramCode": "param_13478", "isMain": true, "sortNumber": 1, "paramNameEn": "Contact Material", "paramName": "触头材质", "paramValue": "磷青铜" }, { "paramValueEnForSearch": -1, "paramValueEn": "Without LED", "paramCode": "param_13477", "isMain": true, "sortNumber": 1, "paramNameEn": "LED", "paramName": "LED", "paramValue": "不带LED" }, { "paramValueEn": "-40℃~+85℃", "paramCode": "param_13480_s", "isMain": true, "sortNumber": 1, "paramNameEn": "Operating Temperature Range", "paramName": "工作温度范围", "paramValue": "-40℃~+85℃" } ], "parentCatalogId": 365, "brandId": 11722, "brandNameEn": "XKB Connection", "maxBuyNumber": -1, "isHot": false } } ```
T0jan commented 2 weeks ago

fixed both in pull request #236. Second one was caused by a too long part name, Inventree allows only 100 characters in the part name, there is now an error message to report this specific error in the gui.

NightSkySK commented 2 weeks ago

@T0jan thank you, the implemented solution looks solid. Let's hope, it will be merged to main and release soon.

eeintech commented 2 weeks ago

Fixed in #236