3

I want to make a request to a public colour analysis API:

http://mkweb.bcgsc.ca/color-summarizer?url=http://www.undistraction.com/vangogh/images/fisherman_s_wife_on_the_beach-8.jpg&precision=vlow&num_clusters=7&json=1&histogram=0&pixel=0

If I put this URL into Chrome's address bar, I get a JSON object returned after about 10 secs, however when making the request from Node , I only ever get an ESOCKETTIMEDOUT error.

request.get({
  uri: 'http://mkweb.bcgsc.ca/color-summarizer?url=http://www.undistraction.com/vangogh/images/fisherman_s_wife_on_the_beach-8.jpg&precision=vlow&num_clusters=7&json=1&histogram=0&pixel=0',
  timeout: 60000,
 })
.on('error', (error) => {
  console.log(error); // ESOCKETTIMEDOUT
})
.on('finish', (body) => {
  // Happy place
});

What could be causing this error?

Undistraction
  • 42,754
  • 56
  • 195
  • 331

1 Answers1

2

I would suspect that it's because you have no User Agent in the headers.

Maybe try:

request.get({
  uri: 'http://mkweb.bcgsc.ca/color-summarizer?url=http://www.undistraction.com/vangogh/images/fisherman_s_wife_on_the_beach-8.jpg&precision=vlow&num_clusters=7&json=1&histogram=0&pixel=0',
  timeout: 60000,
  headers: {'User-Agent': 'Some user agent string'}
});

Maybe you need to copy the user agent string from your browser. Another possible solutions could be no correct cookie etc. Are you sure you are authorized to hit that endpoint?

See this answer for more info:

Community
  • 1
  • 1
rsp
  • 107,747
  • 29
  • 201
  • 177
  • Thanks for the suggestions. I've tried with several user agents, all with the same results and the endpoint is definitely public. – Undistraction Feb 13 '17 at 14:27