yoavaviram / python-amazon-simple-product-api

A simple Python wrapper for the Amazon.com Product Advertising API ⛺
Apache License 2.0
817 stars 212 forks source link

Error: expected string or bytes-like object #155

Open sergioteula opened 5 years ago

sergioteula commented 5 years ago

I'm running my code on a server, and the connection to Amazon works correct when I first boot at the server, but after some requests (about 3 or 4) it fails all the time. If I restart the server it starts working again, but then fails on the same previous situation. I've tried changing the IP from the server, to check if my IP was blocked. But that wasn't the case. I'm not getting a clear error from the API, so I can't figure out how to solve the issue. Also, I've tried accessing the API directly and it works, so maybe is not an issue related with Amazon servers.

Here is my code:

region_options = bottlenose.api.SERVICE_DOMAINS.keys()
amazon = AmazonAPI(key, secret, tag, region='ES', MaxQPS=0.9, Timeout=6)
product = amazon.lookup(ItemId=asin)

And here is what I get:

Traceback (most recent call last):
  File "/root/androizz_test/scrapers/scraper_amazon.py", line 51, in amazonGetData
    product = amazon.lookup(ItemId=c)
  File "/usr/local/lib/python3.5/dist-packages/amazon/api.py", line 174, in lookup
    response = self.api.ItemLookup(ResponseGroup=ResponseGroup, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/bottlenose/api.py", line 274, in __call__
    {'api_url': api_url, 'cache_url': cache_url})
  File "/usr/local/lib/python3.5/dist-packages/bottlenose/api.py", line 235, in _call_api
    return urllib2.urlopen(api_request, timeout=self.Timeout)
  File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.5/urllib/request.py", line 466, in open
    response = self._open(req, data)
  File "/usr/lib/python3.5/urllib/request.py", line 484, in _open
    '_open', req)
  File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 1297, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/usr/lib/python3.5/urllib/request.py", line 1254, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "/usr/lib/python3.5/http/client.py", line 1107, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.5/http/client.py", line 1147, in _send_request
    self.putheader(hdr, value)
  File "/usr/lib/python3.5/http/client.py", line 1083, in putheader
    if _is_illegal_header_value(values[i]):
TypeError: expected string or bytes-like object

Do you have any idea? Thanks a lot in advance!