0

なぜ NameError: name 'amazon' が定義されていないのですか??

それが機能していない場合、それは問題ではありません。

しかし、amazon_api() 関数の場合、「name 'amazon' is not defined」というエラーになります。

エラーなしで amazon_api() 関数を使用するにはどうすればよいですか??

import bottlenose
from bs4 import BeautifulSoup


def item_search(keywords, search_index="Toys", item_page= 1):
    response = amazon.ItemSearch(SearchIndex=search_index, Keywords=keywords, ItemPage=item_page, ResponseGroup="Large")
    soup = BeautifulSoup(response, 'lxml')
    return soup.find('item')

def item_Lookup(item_id):
    response = amazon.ItemLookup(ItemId= item_id,  ResponseGroup="Images")
    soup = BeautifulSoup(response, 'lxml')
    return soup.find('largeimage')

def amazon_api():
    api_id = 'your api_id'
    api_key = 'your api_key'
    tag_id = 'your tag_id'

    amazon = bottlenose.Amazon(api_id,api_key,tag_id)    
    item = item_search('nike', search_index="All", item_page= 1)
    asin = item.find('asin').text

    print(asin)
    img = item_Lookup(asin)
    print(img)

amazon_api()

トレースバック (最後の最後の呼び出し): ファイル "C:\Python34\bottlenose.py"、28 行目、amazon_api() ファイル "C:\Python34\bottlenose.py"、21 行目、amazon_api item = item_search('nike ', search_index="All", item_page= 1) ファイル "C:\Python34\bottlenose.py"、6 行目、item_search 応答 = amazon.ItemSearch(SearchIndex=search_index, Keywords=keywords, ItemPage=item_page, ResponseGroup="大") NameError: 名前 'amazon' が定義されていません

4

0 に答える 0