Max Dubinin
Max Dubinin

Reputation: 224

PhantomJS, Capybara, Poltergeist failed to reach server

I'm working with poltergeist for the first time, so I don't really know what I'm doing but I couldn't find any solution on the web. Please tell me if any information is missing.

Error message:

Capybara::Poltergeist::StatusFailError: Request failed to reach server, check DNS and/or server status

this issue doesn't happen on production but only on development and staging environment.

This line of code is the one that is making the trouble

phantomjs_options: ['--ignore-ssl-errors=yes', '--ssl-protocol=any', '--load-images=no', '--proxy=localhost:9050', '--proxy-type=socks5']

without '--proxy=localhost:9050' everything's working perfectly on every environment but I don't want to delete it in case it's critical for the production.

I've also noticed that on staging/development there's no 9050 port listening but on production there is one

full config code part (capybara_drivers.rb):

Capybara.register_driver :polt do |app|
  Capybara::Poltergeist::Driver.new(
      app,
      js_errors: false, # break on js error
      timeout: 180, # maximum time in second for the server to produce a response
      debug: false, # more verbose log
      window_size: [1280, 800], # not responsive, used to simulate scroll when needed
      inspector: false, # use debug breakpoint and chrome inspector,
      phantomjs_options: ['--ignore-ssl-errors=yes', '--ssl-protocol=any', '--load-images=no', '--proxy=localhost:9050', '--proxy-type=socks5']

  )
end

Upvotes: 1

Views: 1752

Answers (1)

Thomas Walpole
Thomas Walpole

Reputation: 49890

Sounds like your production environment needs to make outbound connections through a socks5 proxy, and your other environments don't. You'll need to make the configuration dependent on environment

Capybara.register_driver :polt do |app|
  phantomjs_options = ['--ignore-ssl-errors=yes', '--ssl-protocol=any', '--load-images=no']
  phantomjs_options.push('--proxy=localhost:9050', '--proxy-type=socks5') if Rails.env.production?
  Capybara::Poltergeist::Driver.new(
      app,
      js_errors: false, # break on js error
      timeout: 180, # maximum time in second for the server to produce a response
      debug: false, # more verbose log
      window_size: [1280, 800], # not responsive, used to simulate scroll when needed
      inspector: false, # use debug breakpoint and chrome inspector,
      phantomjs_options: phantomjs_options
  )
end

Upvotes: 3

Related Questions