t3chnoboy / amazon-product-api

:credit_card: Amazon Product Advertising API client
365 stars 104 forks source link

TypeError: Key must be a buffer #92

Closed awaistechverx closed 6 years ago

awaistechverx commented 6 years ago

i am getting this error when i put my code in production:

crypto.js:91 this._handle.init(hmac, toBuf(key)); ^

TypeError: Key must be a buffer
    at TypeError (native)
    at new Hmac (crypto.js:91:16)
    at Object.Hmac (crypto.js:89:12)
    at generateSignature (/home/ubuntu/Cruiserhandlebars/node_modules/aws-product-api/index.js:15:23)
    at GenerateURL (/home/ubuntu/Cruiserhandlebars/node_modules/aws-product-api/index.js:102:40)
    at AmazonController.Query (/home/ubuntu/Cruiserhandlebars/node_modules/aws-product-api/index.js:109:15)
    at Timeout._onTimeout (/home/ubuntu/Cruiserhandlebars/app/controllers/PricingAPI/cjCron.js:160:25)
    at ontimeout (timers.js:365:14)
    at tryOnTimeout (timers.js:237:5)
    at Timer.listOnTimeout (timers.js:207:5)
awaistechverx commented 6 years ago

My Bad sorry :p

jurgob commented 6 years ago

I had the same problem:

kamana_api    |   TypeError: Key must be a buffer
kamana_api    |       at TypeError (native)
kamana_api    |       at new Hmac (crypto.js:92:16)
kamana_api    |       at Object.Hmac (crypto.js:90:12)
kamana_api    |       at generateSignature (/usr/src/app/node_modules/amazon-product-api/lib/utils.js:4:21)
kamana_api    |       at generateQueryString (/usr/src/app/node_modules/amazon-product-api/lib/utils.js:107:38)
kamana_api    |       at Object.browseNodeLookup (/usr/src/app/node_modules/amazon-product-api/lib/index.js:14:15)
kamana_api    |       at Promise (/usr/src/app/amazon.js:80:57)
kamana_api    |       at _amazonAction (/usr/src/app/amazon.js:80:10)
kamana_api    |       at amazonRequest (/usr/src/app/amazon.js:66:19)
kamana_api    |       at next (native)

but only if I run this inside a docker container.

what did you do to solve it?

jurgob commented 6 years ago

Sorry, my bad as well, I was passing empty credentials:

amazon.createClient({
  awsId: credentials.AWS_ID,
  awsSecret: credentials.AWS_SECRET,
  awsTag: credentials.AWS_TAG
});

AWS_ID, AWS_SECRET and AWS_TAG were empty string. Maybe it could be a good Idea passing a more specific error

camyyssa commented 6 years ago

👍

I had the same error caused by passing empty credentials. Thank you @jurgob for specifying what the mistake was! ❤️