0

I am new to casper js and I would like to retrieve a json object from a get request. The message I get is the following :

Loading resource failed with status=fail: https://api.twitter.com/1.1/search/tweets.json?q=casperjs

Here is my code :

var casper = require('casper').create({
  verbose: true,
  logLevel: 'debug',
  pageSettings: {
    loadImages: false,
    loadPlugins: false,
    userAgent: 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36'
  }
});


casper.start().then(function() {
    this.open('https://api.twitter.com/1.1/search/tweets.json?q=casperjs', {
        method: 'get',
        headers: {
            'Accept': 'application/json'
        }
    });
});

casper.then(function() {
    require('utils').dump(JSON.parse(this.getPageContent()));
});

casper.run(function() {
    this.exit();
});

I have spent lot of time to understand what was going wrong without any succeed. I have not find other similar problems on stack... meaning I must do something wrong.

Thank you for your help

my configuration (from brew info):

  • casperjs: stable 1.0.4 (bottled), devel 1.1-beta3, HEAD
  • phantomjs: stable 2.0.0 (bottled), HEAD
  • Can't reproduce your issue with the CasperJS master and PhantomJS 2.0.0 on windows. – Artjom B. May 22 '15 at 18:04
  • May be it is because I'm on mac since the master branch of casperjs hosts the development version. – Appartement Dupleix May 26 '15 at 11:00
  • A problem like this shouldn't originate from CasperJS. Perhaps it's an SSL problem. Have you tried to use some of the available command line options like `--ssl-protocol=any` and `--ignore-ssl-errors=true`? – Artjom B. May 26 '15 at 13:18
  • It works with `--ignore-ssl-errors=true` but doesn't with `--ssl-protocol=any`... I really don't understand why? Anyway, thank you very much for your help ! – Appartement Dupleix May 27 '15 at 14:09
  • possible duplicate of [PhantomJS failing to open HTTPS site](http://stackoverflow.com/questions/12021578/phantomjs-failing-to-open-https-site) – Artjom B. May 27 '15 at 14:19

2 Answers2

0

As suggested by @Artjom B., I used the following command line option --ignore-ssl-errors=trueand the file suceeded in loading the json.

0

For anyone else looking, as well as ignoring ssl errors if you are using a proxy ensure that the proxy is working correctly and make sure that the proxy has been properly authenticated.

If it has not been authenticated then it will just return a lookup fail not pointing you to the proxy as the issue

James McClelland
  • 555
  • 4
  • 16