Closed NightSkySK closed 3 weeks ago
Hello @NightSkySK
I am not very familiar with TME's API, is it supposed to return prices by default, or does it need some kind of parameter in the call to add them to the response? I would appreciate if you'd find more info regarding this and we could try to add it to a future release 😃
I investigated a bit kintree\search\tme_api.py
so fetching product info from TME API is running in three or four steps:
First two are working without any problem, only /Products/GetPrices causing error
[INFO] Warning: API data download failed (HTTP Error)
From my debug investigation. error is result of kintree\common\tools.py
line 99 url_data = urllib.request.urlopen(url)
url_data = urllib.request.urlopen(url)
data = url_data.read()
data_json = json.loads(data.decode('utf-8'))
return data_json
except (socket.timeout, requests.exceptions.ConnectTimeout, requests.exceptions.ReadTimeout):
cprint(f'[INFO]\tWarning: {filetype} download socket timed out ({timeout}s)', silent=silent)
except (urllib.error.HTTPError, requests.exceptions.ConnectionError):
cprint(f'[INFO]\tWarning: {filetype} download failed (HTTP Error)', silent=silent)
and rise requests.exceptions.ConnectionError
I've checked the request body against TME API Manual and all seems to be correct. I've tried, also to replace /Products/GetPrices
with Products/GetPricesAndStocks
endpoint which are very similar but also the same error appears in the same moment.
I hope @T0jan will find some time to have a look on this case as I couldn't find root cause of this error.
Sadly not a quick fix here. I took a look on it and the API reports an generic 400 error back without any explanation why, so there needs to be done some try and error here to figure out what the actual error is. Note: just dropping the currency parameter for the request does not work, it only changes the error to a 406.
Intrestinly in TME Developers Sandbox I'm able to receive the respond 200 to the request:
documentation says that GrossPrice
is optional but here seems to be passed in request, maybe this is the difference?
@NightSkySK yeah I was able to get the same result in the sandbox too. adding the GrossPrice
parameter to the request in kintree didn't change the outcome for me. My current idea is, that the server for whatever reason does not understand additional parameters like Currency
. If I have some time I will investigate this further, but if you have the motivation feel free to share the results as well.
Is it possible to print request generated urllib.request.Request(url, data, headers)
to cURL or something similar?
kinda, but I personally think its more productive to just run the command in an interactive python console and check the individual urllib objects right there.
Finally found some time to get back to this and figured it out. The TME API for some reason needs the parameters to be in alphabetical order and they weren't for only the pricing request. I restructured the code a bit to account for this and allow for easier future expansion if needed.
Was fixed in https://github.com/sparkmicro/Ki-nTree/releases/tag/1.1.4, closing here
I've tried serval components creation via TME API and none of them contain supplier prices once uploaded to Inventree.
as example YAML cached result:
All other API which I've tested like LCSC, Mouser, and Digi-Key have prices in cached yaml: