Tuesday 23 May 2017

intermittent access denied from airbnb calendar on using node request

I'm trying to write a very simple solution to download and parse a calendar file from my Airbnb. Airbnb provides the calendar in ical format, with a unique url for each user such as:

https://www.airbnb.com/calendar/ical/1234.ics?s=abcd Where those numbers (1234/5678) are unique hex keys to provide some security.

Whenever I hit my (private) url it replies instantly with an ical if I'm using a browser. I can be using any browser, even one from a different country that has never visited airbnb.com before. (I've got remote access to a server I tried it from when debugging.)

In nodejs it works only about 10% of the time. Most of the time I get a 403 error with the text of You don't have permission to access (redacted url) on this server.

Example code:

const request = require('request');
request.get(url, (error, response, body) => {
  if (!error && response.statusCode === 200) {
    return callback(null, body);
  }
  return callback('error');
});

This is using the request package here: https://github.com/request/request

I've set it up in an async.whilst loop and it takes about 50 tries to pull down a success, if I set a multi-second delay between each one. (Btw, https://github.com/caolan/async is awesome, so check that if you haven't.)

If it failed EVERY time, that'd be different, but the fact that it fails only occasionally really has me stumped. Furthermore, browsers seem to succeed EVERY time as well.

curl [url] also works, every time. So is there something I'm not specifying in the request that I need to?



via Will Shaver

No comments:

Post a Comment