Reputation: 129
why NameError: name 'amazon' is not defined??
it is no plablem, if it is no in function.
but if in amazon_api() function, it is error 'name 'amazon' is not defined'.
how can i use amazon_api() function without Error ??
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()
Traceback (most recent call last): File "C:\Python34\bottlenose.py", line 28, in amazon_api() File "C:\Python34\bottlenose.py", line 21, in amazon_api item = item_search('nike', search_index="All", item_page= 1) File "C:\Python34\bottlenose.py", line 6, in item_search response = amazon.ItemSearch(SearchIndex=search_index, Keywords=keywords, ItemPage=item_page, ResponseGroup="Large") NameError: name 'amazon' is not defined
Upvotes: 0
Views: 161