sergioteula / python-amazon-paapi

Amazon Product Advertising API 5.0 wrapper for Python 💰
MIT License
228 stars 46 forks source link

Invalid Asin in a List #82

Closed barbax7 closed 2 years ago

barbax7 commented 3 years ago

Hi @sergioteula As said in the Telegram group, in the get_items request, if we pass a list of asins and inside it there is an invalid asin, it isn't contemplated by the library.

But, if we run the request through the scratchpad, we get this response (with items ['B07VMG4ZL5','B084Q4T9NM'] in Italian marketplace):

{
 "Errors": [
  {
   "__type": "com.amazon.paapi5#ErrorData",
   "Code": "InvalidParameterValue",
   "Message": "The ItemId B07VMG4ZL5 provided in the request is invalid."
  }
 ],
 "ItemsResult": {
  "Items": [
   {
    "ASIN": "B084Q4T9NM",
    "DetailPageURL": "https://www.amazon.it/dp/B084Q4T9NM?tag=ok05d-21&linkCode=ogi&th=1&psc=1",
    "ItemInfo": {
     "Title": {
      "DisplayValue": "Sony KD-49XH9505 - Televisore 49\" 4K Ultra HD HDR Full Array LED con Android TV (X-Motion Clarity, 4K HDR Processor X1 Ultimate, schermo TRILUMINOS, X-tended Dynamic Range PRO, Wi-Fi), nero",
      "Label": "Title",
      "Locale": "it_IT"
     }
    }
   }
  ]
 }
}

Is there a way to get the items and the errors both?

barbax7 commented 3 years ago

I think that the best way could be adding in items returned by get_items an object with informations about not found asin Like:

class NotValidAsin():
    def __init__(self, asin, error):
        self.asin = asin
        self.error = error
sergioteula commented 2 years ago

This is already solved in the new version https://github.com/sergioteula/python-amazon-paapi/releases/tag/v4.2.0

I have added a new parameter to get_items to include not available ones as items with the ASIN code but other attributes as None. So you can check for non available items with if product.item_info is None.