sergioteula / python-amazon-paapi Goto Github PK
View Code? Open in Web Editor NEWAmazon Product Advertising API 5.0 wrapper for Python 💰
License: MIT License
Amazon Product Advertising API 5.0 wrapper for Python 💰
License: MIT License
Don't have support for multiple ASINs in the same API request?
I believe my understanding is correct that the maximum requests per second currently is one request per second? For users with a higher rate limit it would be ideal to be able to either turn off throttling or set throttling to a number greater than one.
I suggest allowing any positive number to allow more requests per second, and to allow 0
or False
to disable throttling altogether.
Happy to make a PR at some point when I find time if this makes sense and would be helpful!
what do i need to enter in the tag value in the amazonapi?
We want to implement specific operations for each different exception, but currently cannot do that e.g
amazon.exception.AmazonException: ApiException: (401) Reason: Unauthorized HTTP response headers: HTTPHeaderDict({'Server': 'Server', 'Date': 'Thu, 01 Jul 2021 09:29:50 GMT', 'Content-Type': 'application/json', 'Content-Length': '320', 'Connection': 'keep-alive', 'x-amz-rid': '6M7ZZBARR7KPJ8YEV5JS', 'x-amzn-RequestId': 'd920d9d8-955c-4901-8ec5-e9402df5493e', 'Vary': 'Content-Type,Accept-Encoding,X-Amzn-CDN-Cache,X-Amzn-AX-Treatment,User-Agent', 'Permissions-Policy': 'interest-cohort=()'}) HTTP response body: {"__type":"com.amazon.paapi5#InvalidSignatureException","Errors":[{"Code":"InvalidSignature","Message":"The request has not been correctly signed. If you are using an AWS SDK, requests are signed for you automatically; otherwise, go to https://webservices.amazon.it/paapi5/documentation/sending-request.html#signing."}]}
how handle the InvalidSignatureException?
In amazon/parse.py
, the class named "Class" is confusing - my suggestion would be to create specifically named class instances for each entity. Something like the following:
class AmazonBase:
pass
class AmazonProduct(AmazonBase):
pass
class AmazonProductInfo(AmazonBase):
pass
class AmazonContributor(AmazonBase):
pass
etc.
Then, when instantiating (for instance) product.info, we would instantiate product.info = AmazonProductInfo()
. A contributor would be contributor = AmazonContributor()
.
When debugging, rather than seeing an error like TypeError: Object of type Class is not JSON serializable
, which is confusing and doesn't let the user know that the error is part of the Amazon Product API logic, it would be more specific, for instance TypeError: Object of type AmazonContributor is not JSON serializable
.
Let me know your thoughts @sergioteula ? Happy to write a PR if it's helpful.
Your library handle all exceptions internally making it impossible for end user to know if a key is revoked, or he is calling api too fast or what's going wrong.
Raise the actual exception and let end users handle it.
For this reason alone I had to migrated to https://github.com/alefiori82/amazon-paapi5 which handles exceptions in a better way.
It would be really nice to have a test suite for the repo. In particular, including something like mocks.py
that includes a mock product returned by this repo would help users to unit test our applications.
I may have time to start on this - I focus only on books but could be a good start to creating a test suite for this repo.
Would also be nice to show code coverage and test suite status on CI.
Hello there
Whit this link (and others also):
https://www.amazon.it/gp/aw/d/B08QJPMM2J?pf_rd_m=A11IL2PNWYJU7H&storeType=ebooks&pf_rd_p=889e88dc-a023-41fa-8871-b0fc0a00d2b4&pf_rd_r=V50DCEG5YY1HAE7AG1JC&pf_rd_s=mobile-hybrid-3&pf_rd_t=30901&ref_=dbs_f_r_shv_ts_889e88dc-a023-41fa-8871-b0fc0a00d2b4_16&pf_rd_i=1728160031
it returns:
InvalidParameterValue","Message":"The value null provided in the request for ItemId is invalid."}]}
in get_product
function.
I'm getting the below error:
HTTP response body: {"__type":"com.amazon.paapi5#TooManyRequestsException","Errors":[{"Code":"TooManyRequests","Message":"The request was denied due to request throttling. Please verify the number of requests made per second to the Amazon Product Advertising API."}]}
I have tried the demo code and have played around with the throttling but still no luck... Any ideas?
from amazon.paapi import AmazonAPI
amazon = AmazonAPI("x", "x", "x", "US", throttling=0.5)
product = amazon.get_product('B01N5IB20Q')
print(product.title)
Originally posted by aashishsaini75 June 9, 2021
@sergioteula I think something is not good with the get_products function, I am passing a list of asins in function to get the price value and also getting the response but the response is not returned in a order of list i am passing like the product[0].prices.price.value response should be the result of first asin of a list but it returned the value randomly of any of the asins.
See the attached images to get better understanding
Context
I am attempting to use search_products() to find all items for a given keyword. So I am inputting one keyword and returning the metadata of the items returned in the search.
However, I am running into a No Response error [AmazonException: ResponseError: NoResults: No results found for your request.]The problem occurs when the input keyword’s total_results_count is less than then item_count.
For example, the keyword, ‘norwegian operation’.
My script is calling search_products like this → products=amazon.search_products(item_count=100, keywords='norwegian operation', search_index = "KindleStore")
And getting the response → [ AmazonException: ResponseError: NoResults: No results found for your request.] From line 292.
Environment
I am using a macOS Catalina Version 10.15.3 and Python 3.7.
Steps to Reproduce Errors
products=amazon.search_products(item_count=100, keywords='norwegian operation', search_index = "KindleStore")
Expected Behavior
This issue arises because the keyword ‘norwegian operation’ only has 40 total_result_count. If you change the item_count to 40 or less it does not raise this error. I would like to get the resulting items regardless of the total results. The paaapi.py allows for a response if there is no results, but not if the total_result_count is less than the item_count.
Hey,
Thanks for creating this great module. We know you may still create the new features. But would you mind to share any plan or schedule to build getBrowseNodes function in this module in future? Since we need this function for our project.
Thanks again!
Hello there
Today i'm receiving a very strange error.
ApiException: (500) Reason: Internal Server Error HTTP response headers: HTTPHeaderDict({'Server': 'Server', 'Date': 'Tue, 12 Jan 2021 17:53:45 GMT', 'Content-Type': 'application/json', 'Content-Length': '168', 'Connection': 'keep-alive', 'x-amz-rid': '565JTC4ZNV1CWMKZYWAH', 'x-amzn-RequestId': 'f0176e0a-fa38-4e60-b179-eddb1aa62d42', 'Vary': 'Content-Type,Accept-Encoding,X-Amzn-CDN-Cache,X-Amzn-AX-Treatment,User-Agent'}) HTTP response body: {"__type":"com.amazon.coral.service#InternalFailure","message":"The request processing has failed due to some unknown error, exception or failure. Please retry again."}
I don't know the reason why, it doesn't work on webapp and local running. On scratchpad my key works.
I feel like our API didn't cover CustomerReviews
in the result. So I'm wondering if it's possible to include CustomerReviews into raw_info result.
Is sales rank still available through the API? If so, it'd be great to have access to that.
Hi, i'm really appreciating your work! I have one thing to ask. I can use Amazon Warehouse link to get the product and this is really cool. I found the way to get the lowest price in the warehouse and that's fantastic. The only thing i can't find is the URL with tag for the Amazon Warehouse's page of the product.
There is 1 URL and goes always on the page of the standard Amazon.
I hope you can understand what i'm saying and help me 🤣
Thank you again
Hello,
when I start a product search with ASIN B084FCWBLZ I get an exception "AttributeError: 'NoneType' object has no attribute 'small' in line 652". And no product is returning. The item is listed on amazon but is actually not available. I use DE as region.
Hi,
Prices seems to return pvp and price, but not currency (but it is returned in offers).
For consistency, there should be a product.prices.currency
Thanks
Hi, I'm trying to get a few items in a single request and got an AsinNotFoundException error. How do I know which one ASIN from the list caused the error?
items = amazon.get_items(['XXXX', 'YYYYY'])
Thanks!
ASINs which exist sometimes return the product without an asin value in the response object, and are sometimes only accepted when they are all uppercase. maybe the asin can be converted to uppercase and inserted into the object asin if it doesnt exist in the response?
Hi, I am using your code, and it is fantastic.
But I am getting the error "Too many requests", I am calling the api with a time.sleep(2) to wait one or two seconds before call again the api. I don't know if it is relative to the api or other problem.
I am not using the api credentials y other programs.
Thanks
@sergioteula I know in a recent patch you removed the "structure" file, is it okay if you could please retrieve it or restore it to the site as I am struggling to get data such as offer price without the structure.
dir(a.product.dimensions) duce_ex__', 'repr', 'setattr', 'sizeof', 'str', '__subcl
['class', 'delattr', 'dict', 'dir', 'doc', 'eq', 'format',
'ge', 'getattribute', 'gt', 'hash', 'init', 'init_subclass', 'le', 'lt', 'module', 'ne', 'new', 'reduce', 'reduce_ex', 'repr', 'setattr', 'sizeof', 'str', 'subclasshook', 'weakref', 'height', 'lenght', 'width']
a.product.dimensions.length
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'Class' object has no attribute 'length'
a.product.dimensions.lenght
<amazon.parse.Class object at 0x03319C70>
I don't see the functions for creating ad campaigns, groups etc. So is this just the product api or advertising as well?
Hello!
A lot of times when I use the min_discount parameter on the "search_products" method I experience two issues:
I've tried to access only the IT marketplace.
Here's a test case code snippet:
min_discount = 70
products = client.search_products(keywords="pc,usb", min_discount=min_discount, item_count=10)
for product in products:
discount = product.prices.price.savings.percentage
if not discount or discount < min_discount:
continue
print("[{}%] {} {}".format(discount, product.title, product.url))
print(product.info.product_group)
print("---")
Actual Price: $108 + $191 shipping
Current: 108.00
Wanted: 299.00
would love this added. great work btw!
In get_product
function there is a split(",")
method that split passed string and if the returned list's lenght is greater than one, it raises an error.
I think it could be better that with get_product
function you get only the product of first asin (or url), ignoring the rest.
It could be useful also when you have urls like https://www.amazon.it/canzone-Achille-Madeline-Miller-ebook/dp/B07LGBM18M?__mk_it_IT=%C3%85M%C3%85%C5%BD%C3%95%C3%91&crid=R96BEWN0UBFE&dchild=1&keywords=la+canzone+di+achille&qid=1615931295&sprefix=la+canzone,aps,190&sr=8-2&linkCode=sl1&tag=flow074-21&linkId=6f4cfda5b4222977473aa183b503e2db&language=it_IT&ref_=as_li_ss_tl
where there are two commas inside.
What do you think?
I get the following error if the product is not available anymore.
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-129-1b28dcb36038> in <module>
----> 1 product = amazon.get_product('B071YR89XJ')
~/dev/project/lib/python3.6/site-packages/amazon/paapi.py in get_product(self, product_id, condition, merchant, async_req)
166 'get_products for multiple requests')
167 return self.get_products(product_id, condition=condition, merchant=merchant,
--> 168 async_req=async_req)[0]
169
170 def search_products(self, item_count=10, item_page=1, items_per_page=10, keywords=None,
TypeError: 'NoneType' object is not subscriptable
eg. page: https://www.amazon.com/natiga-ng-0141-Cherrys-Enamel-Brooch/dp/B071YR89XJ
even the amazon page shows 404 but product used to be available.
in this case error handling could be improved.
Thanks
no issue except my brain
Thank you for building this repo, and for being so responsive! Also thanks for making the license change.
I'm getting this exception in my code after a 400 response from Amazon:
Exception ignored in: <function ApiClient.__del__ at 0x10e10e268>
Traceback (most recent call last):
File "/Users/myuser/.virtualenvs/mysite/lib/python3.7/site-packages/paapi5_python_sdk/api_client.py", line 104, in __del__
File "/usr/local/var/pyenv/versions/3.7.0/lib/python3.7/multiprocessing/pool.py", line 539, in close
TypeError: 'NoneType' object is not callable
I'm still investigating and will make a PR if I find any issues I can fix, but leaving this here for now in case other users encounter the same problem.
Thank you for useful wrapper module!
I was just looking for such software.
It's very helpful!
But I found a symptomatology that the script execution cannot be finished...
I ran the following code for my test on both Mac and Windows.
main.py:
# -*- coding: utf-8 -*-
from amazon_paapi import AmazonApi
KEY = "XXXX"
SECRET = "XXXX"
TAG = "XXXX"
COUNTRY = "JP"
if __name__ == "__main__":
amazon = AmazonApi(KEY, SECRET, TAG, COUNTRY)
items = amazon.get_items(['B01N5IB20Q', 'B01F9G43WU'])
for item in items:
print(item.images.primary.large.url) # Primary image url
print(item.offers.listings[0].price.amount) # Current price
On mac, the execution immediately after launching the terminal didn't finish successfully.
(It didn't finish until I used Control-C)
(The second and subsequent executions finished successfully)
Terminal on Mac:
testuser@Mac test % python main.py
https://m.media-amazon.com/images/I/41cKE7Id6AL._SL500_.jpg
4490.0
https://m.media-amazon.com/images/I/41s20oziIJL._SL500_.jpg
4424.0
(sometimes freezes here )
On the other hand, the execution on Windows always couldn't finish successfully.
It always didn't finish until I used Control-C.
My environment:
3.8.8
on both OS4.1.1
Catelina 10.15.7
Windows 7
Do you know the cause and workaround?
This wrapper is awesome!
Please add the ability to get the star rating of a product (4/5 for example) and customer reviews at the bottom of product pages.
I need to send requests to webservices.amazon.it
through a proxy server. How can I set it?
Thank you for picking up the pa api5 library develoment.
I have few queries as below:
1. Why are you normalizing links by appending .AC.?
The image url shows highest quality available with if you remove all link functions xx part and keep .jpg simply. This way links are little small and unified with other library.
2. Can we setup a chat on Telegram, gitter or slack instead so users can us that for non-issue type queries for faster development?
paapi5 library is much needed right now and a chat will fasten the development, discussion and suggestion.
amazon.get_browsenodes(browse_nodes=['3375301']) gives an error after adding import pprint, six to the parse.py file:
NameError Traceback (most recent call last)
in
1 bnData = amazon.get_browsenodes(browse_nodes=['3375301'])
2
----> 3 print(bnData)
~/opt/miniconda3/lib/python3.7/site-packages/amazon/parse.py in repr(self)
59
60 def repr(self):
---> 61 return self.to_str()
62
63 def eq(self, other):
~/opt/miniconda3/lib/python3.7/site-packages/amazon/parse.py in to_str(self)
56
57 def to_str(self):
---> 58 return pprint.pformat(self.to_dict())
59
60 def repr(self):
~/opt/miniconda3/lib/python3.7/site-packages/amazon/parse.py in to_dict(self)
49 else:
50 result[attr] = value
---> 51 if issubclass(BrowseNode, dict):
52 for key, value in self.items():
53 result[key] = value
NameError: name 'BrowseNode' is not defined
Please let me know how to correct. Thanks for this great module.
Would it be possible to use this library to get flash deal prices? Apparently it does the same as the prior library I used that just gives the 'non-flash' deal.
How can i solve this? Thank you!
That's my simple code:
KEY = ""
SECRET = ""
TAG = ""
COUNTRY = "UK"
from amazon.paapi import AmazonAPI
amazon = AmazonAPI(KEY, SECRET, TAG, COUNTRY)
product = amazon.get_product('B01N5IB20Q')
print(product.title)
but I get this error
from amazon.paapi import AmazonAPI
ModuleNotFoundError: No module named 'amazon'
Please can someone help me?
File "venv/local/lib/python2.7/site-packages/amazon/paapi.py", line 652, in get_product
raise exception
AttributeError: 'NoneType' object has no attribute 'small'
Try getting ASIN: 1628603976
I think that the while
loop in search_products is causing more issues than it solves. If someone needs to use the pagination they can use the item_count
and items_per_page
parameters built into the SDK.
As currently implemented the while
loop means that any time a user searches for a product and the search returns fewer than item_count
results they're actually making two calls to the API, not one call.
So, if the user searches for a very specific title, and the API returns one result, but we have item_count
set by default to ten items, the wrapper makes a second (unnecessary) call to Amazon.
Can anyone give me some idea, why I am always getting the same error, again and again, I have also changed the throttle values too.
amazon.exception.AmazonException: ApiException: (401)
Reason: Unauthorized
HTTP response body: {"__type":"com.amazon.paapi5#InvalidSignatureException","Errors":[{"Code":"InvalidSignature","Message":"The request has not been correctly signed. If you are using an AWS SDK, requests are signed for you automatically; otherwise, go to https://webservices.amazon.com/paapi5/documentation/sending-request.html#signing."}]}
Any idea why this is happening?
Hey,
is it possible to search for a (or some) products by keywords (e.g. apple iPhone)?
Nice project! Kind regards
I'm trying to do a request which is working just fine from my local console. But once I try to make the same request from App Engine, I get this error:
ApiException: (401) Reason: Unauthorized HTTP response headers: HTTPHeaderDict({'x-amzn-RequestId': '9c9d9a24-c503-47e7-a912-ca0c79640ec2', 'Content-Length': '321', 'Vary': 'Content-Type,Accept-Encoding,X-Amzn-CDN-Cache,X-Amzn-AX-Treatment,User-Agent', 'Server': 'Server', 'x-amz-rid': 'M2SS3YJWJG78096WQ7R5', 'Connection': 'keep-alive', 'Date': 'Mon, 19 Oct 2020 22:59:44 GMT', 'Content-Type': 'application/json'}) HTTP response body: {"__type":"com.amazon.paapi5#InvalidSignatureException","Errors":[{"Code":"InvalidSignature","Message":"The request has not been correctly signed. If you are using an AWS SDK, requests are signed for you automatically; otherwise, go to https://webservices.amazon.com/paapi5/documentation/sending-request.html#signing."}]}
I will be adding compatibility with product URL, not only product ASIN. This way you will be able to get product information by passing the URL directly.
amazon.exception.AmazonException: ApiException: (401)
Reason: Unauthorized
HTTP response body: {"__type":"com.amazon.paapi5#InvalidSignatureException","Errors":[{"Code":"InvalidSignature","Message":"The request has not been correctly signed. If you are using an AWS SDK, requests are signed for you automatically; otherwise, go to https://webservices.amazon.com/paapi5/documentation/sending-request.html#signing."}]}
Any idea why this is happening?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.