Amazon AffiliateのAPIを実行する事を考えております。
##概要
サンプルプログラムを以下よりダウンロードし、SAMPLEコードと以下の箇所変更して実行しております。(ローカル環境で一回のみ)
https://webservices.amazon.com/paapi5/documentation/quick-start/using-sdk.html
python
1access_key = "hogehogege" 2secret_key = "hogehoge" 3partner_tag = "hoge" 4host = "webservices.amazon.co.jp" 5region = "us-west-2" 6marketplace="www.amazon.co.jp"
ですが、実行後に、以下のエラーが生じてしまいます。認証情報等は良さそうなのですが、リクエスト数が多すぎると言われても、一度しかしていないので、原因が不明です。。。
Error calling PA-API 5.0! Status code: 429 Errors : {"__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."}]} Request ID: ef46350f-a370-409a-b416-311e39175549
##知りたい事
原因が不明のため、どなたか解決につながるヒントをいただけないでしょうか?
##コード
python
1# -*- coding: utf-8 -*- 2 3""" 4 Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. 5 6 Licensed under the Apache License, Version 2.0 (the "License"). 7 You may not use this file except in compliance with the License. 8 A copy of the License is located at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 or in the "license" file accompanying this file. This file is distributed 13 on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 14 express or implied. See the License for the specific language governing 15 permissions and limitations under the License. 16""" 17 18""" 19 ProductAdvertisingAPI 20 21 https://webservices.amazon.com/paapi5/documentation/index.html 22 23""" 24 25""" 26This sample code snippet is for ProductAdvertisingAPI 5.0's GetItems API 27 28For more details, refer: 29https://webservices.amazon.com/paapi5/documentation/get-items.html 30 31""" 32 33from paapi5_python_sdk.api.default_api import DefaultApi 34from paapi5_python_sdk.condition import Condition 35from paapi5_python_sdk.get_items_request import GetItemsRequest 36from paapi5_python_sdk.get_items_resource import GetItemsResource 37from paapi5_python_sdk.partner_type import PartnerType 38from paapi5_python_sdk.rest import ApiException 39 40 41def parse_response(item_response_list): 42 """ 43 The function parses GetItemsResponse and creates a dict of ASIN to Item object 44 :param item_response_list: List of Items in GetItemsResponse 45 :return: Dict of ASIN to Item object 46 """ 47 mapped_response = {} 48 for item in item_response_list: 49 mapped_response[item.asin] = item 50 return mapped_response 51 52 53def get_items(): 54 """ Following are your credentials """ 55 """ Please add your access key here """ 56 access_key = "hoge" 57 58 """ Please add your secret key here """ 59 secret_key = "hoge" 60 61 """ Please add your partner tag (store/tracking id) here """ 62 partner_tag = "hoge" 63 64 """ PAAPI host and region to which you want to send request """ 65 """ For more details refer: https://webservices.amazon.com/paapi5/documentation/common-request-parameters.html#host-and-region""" 66 host = "webservices.amazon.co.jp" 67 region = "us-west-2" 68 69 """ API declaration """ 70 default_api = DefaultApi( 71 access_key=access_key, secret_key=secret_key, host=host, region=region 72 ) 73 74 """ Request initialization""" 75 76 """ Choose item id(s) """ 77 item_ids = ["059035342X", "B00X4WHP5E", "B00ZV9RDKK"] 78 79 """ Choose resources you want from GetItemsResource enum """ 80 """ For more details, refer: https://webservices.amazon.com/paapi5/documentation/get-items.html#resources-parameter """ 81 get_items_resource = [ 82 GetItemsResource.ITEMINFO_TITLE, 83 GetItemsResource.OFFERS_LISTINGS_PRICE, 84 ] 85 86 """ Forming request """ 87 88 try: 89 get_items_request = GetItemsRequest( 90 partner_tag=partner_tag, 91 partner_type=PartnerType.ASSOCIATES, 92 marketplace="www.amazon.co.jp", 93 condition=Condition.NEW, 94 item_ids=item_ids, 95 resources=get_items_resource, 96 ) 97 except ValueError as exception: 98 print("Error in forming GetItemsRequest: ", exception) 99 return 100 101 try: 102 """ Sending request """ 103 response = default_api.get_items(get_items_request) 104 105 print("API called Successfully") 106 print("Complete Response:", response) 107 108 """ Parse response """ 109 if response.items_result is not None: 110 print("Printing all item information in ItemsResult:") 111 response_list = parse_response(response.items_result.items) 112 for item_id in item_ids: 113 print("Printing information about the item_id: ", item_id) 114 if item_id in response_list: 115 item = response_list[item_id] 116 if item is not None: 117 if item.asin is not None: 118 print("ASIN: ", item.asin) 119 if item.detail_page_url is not None: 120 print("DetailPageURL: ", item.detail_page_url) 121 if ( 122 item.item_info is not None 123 and item.item_info.title is not None 124 and item.item_info.title.display_value is not None 125 ): 126 print("Title: ", item.item_info.title.display_value) 127 if ( 128 item.offers is not None 129 and item.offers.listings is not None 130 and item.offers.listings[0].price is not None 131 and item.offers.listings[0].price.display_amount is not None 132 ): 133 print( 134 "Buying Price: ", 135 item.offers.listings[0].price.display_amount, 136 ) 137 else: 138 print("Item not found, check errors") 139 140 if response.errors is not None: 141 print("\nPrinting Errors:\nPrinting First Error Object from list of Errors") 142 print("Error code", response.errors[0].code) 143 print("Error message", response.errors[0].message) 144 145 except ApiException as exception: 146 print("Error calling PA-API 5.0!") 147 print("Status code:", exception.status) 148 print("Errors :", exception.body) 149 print("Request ID:", exception.headers["x-amzn-RequestId"]) 150 151 except TypeError as exception: 152 print("TypeError :", exception) 153 154 except ValueError as exception: 155 print("ValueError :", exception) 156 157 except Exception as exception: 158 print("Exception :", exception) 159 160get_items()
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/12 06:03