Watir-Webdriver - Address family not supported by protocol - socket(2) - ruby-on-rails

I have been using watir-webdriver / MiniTest framework for just under a month now and it has been going really well. However the pack that I'm required to run every time a new build is launched contains just under 100 individual tests which takes well over an hour to go through all of them.
This is why I setup a VPS with Ruby, RVM, Watir, Rails and Firefox on a Centos-6-x86_64. This way I don't have to run the scripts on my laptop and wait for them to finish before I can do anything else.
However when I tried to test that watir was working using irb I get the following error:
Errno::EAFNOSUPPORT: Address family not supported by protocol - socket(2)
Test:
[root#V-9876 ~]# irb
1.9.3p448 :001 > require 'watir-webdriver'
=> true
1.9.3p448 :002 > b = Watir::Browser.start 'www.google.com'
Errno::EAFNOSUPPORT: Address family not supported by protocol - socket(2)
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/ lib/selenium/webdriver/common/port_prober.rb:28:in `initialize'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/ lib/selenium/webdriver/common/port_prober.rb:28:in `new'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/ lib/selenium/webdriver/common/port_prober.rb:28:in `block in free?'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/ lib/selenium/webdriver/common/port_prober.rb:26:in `each'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/ lib/selenium/webdriver/common/port_prober.rb:26:in `free?'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/ lib/selenium/webdriver/common/port_prober.rb:5:in `above'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/ lib/selenium/webdriver/firefox/launcher.rb:49:in `find_free_port'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/ lib/selenium/webdriver/firefox/launcher.rb:33:in `block in launch'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/ lib/selenium/webdriver/firefox/socket_lock.rb:20:in `locked'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/ lib/selenium/webdriver/firefox/launcher.rb:32:in `launch'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/ lib/selenium/webdriver/firefox/bridge.rb:24:in `initialize'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/ lib/selenium/webdriver/common/driver.rb:31:in `new'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/ lib/selenium/webdriver/common/driver.rb:31:in `for'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/selenium-webdriver-2.37.0/ lib/selenium/webdriver.rb:67:in `for'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/watir-webdriver-0.6.4/lib/ watir- webdriver/browser.rb:46:in `initialize'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/watir-webdriver-0.6.4/lib/ watir- webdriver/browser.rb:29:in `new'
from /usr/local/rvm/gems/ruby-1.9.3-p448/gems/watir-webdriver-0.6.4/lib/ watir- webdriver/browser.rb:29:in `start'
from (irb):2
from /usr/local/rvm/rubies/ruby-1.9.3-p448/bin/irb:13:in `<main>'1.9.3p4 1.9.3p448 :003 >
I have been researching that error and I have found many sites that claim that it is fixed by disabling ipv6 which I did and I am still getting this error.
Not sure if this makes a difference but I also have NGinX / PHP / MySQL installed on this VPS
EDIT - The ruby file is posted below
require "watir-webdriver"
require 'watir-webdriver'
require 'headless'
headless = Headless.new
headless.start
browser = Watir::Browser.new :ff
browser.goto "http://remove-url-for-this-post.com"
puts ("Starting SearchValSelectFields")
browser.select_list(:id, "edit-select-sector").select("Finance and Accounting")
sleep (5)
browser.select_list(:id, "edit-select-subsector--3").select("All Sub-sector")
browser.select_list(:id, "edit-select-location").select("Singapore")
browser.button(:value,"Search").click
assert(browser.text.include?("Salary and employment forecast"))
browser.screenshots ('..\screenshots\SearchValSelectFields.png')
browser.select_list(:id, "edit-select-sector").select("Select Sector")
sleep(3)
browser.select_list(:id, "edit-select-subsector--2").select("Select Sub-sector")
sleep(3)
browser.select_list(:id, "edit-select-location").select("Select Location")
sleep(3)
browser.button(:value,"Search").click
assert(browser.text.include?("This field is required"))
browser.close
headless.destroy
Any ideas?

Somebody at work managed to fix the issue. He said:
They try to connect twice
first to 127.0.0.1 port 7055
then too ::1 port 7055
second one fails
::1 is localhost of IPv6
so you seem to be connecting localhost
and in your server look at /etc/hosts
localhost resolves to the ::1
So all you have to do is edit your /etc/hosts file and comment out ::1 or remove it if you want

Related

`connect_until_stable' error when trying to use selenium on Heroku RoR

I'm trying to run a file on Heroku that has selenium. However, I get the following error.
/app/vendor/bundle/ruby/3.1.0/gems/selenium-webdriver-4.7.1/lib/selenium/webdriver/common/service_manager.rb:130:in `connect_until_stable': unable to connect to /app/.cache/selenium/chromedriver/linux64/109.0.5414.74/chromedriver 127.0.0.1:9515 (Selenium::WebDriver::Error::WebDriverError)
from /app/vendor/bundle/ruby/3.1.0/gems/selenium-webdriver-4.7.1/lib/selenium/webdriver/common/service_manager.rb:57:in `block in start'
from /app/vendor/bundle/ruby/3.1.0/gems/selenium-webdriver-4.7.1/lib/selenium/webdriver/common/socket_lock.rb:41:in `locked'
from /app/vendor/bundle/ruby/3.1.0/gems/selenium-webdriver-4.7.1/lib/selenium/webdriver/common/service_manager.rb:54:in `start'
from <internal:kernel>:90:in `tap'
from /app/vendor/bundle/ruby/3.1.0/gems/selenium-webdriver-4.7.1/lib/selenium/webdriver/common/service.rb:83:in `launch'
from /app/vendor/bundle/ruby/3.1.0/gems/selenium-webdriver-4.7.1/lib/selenium/webdriver/common/driver.rb:341:in `service_url'
from /app/vendor/bundle/ruby/3.1.0/gems/selenium-webdriver-4.7.1/lib/selenium/webdriver/common/driver.rb:321:in `create_bridge'
from /app/vendor/bundle/ruby/3.1.0/gems/selenium-webdriver-4.7.1/lib/selenium/webdriver/common/driver.rb:74:in `initialize'
from /app/vendor/bundle/ruby/3.1.0/gems/selenium-webdriver-4.7.1/lib/selenium/webdriver/common/driver.rb:47:in `new'
from /app/vendor/bundle/ruby/3.1.0/gems/selenium-webdriver-4.7.1/lib/selenium/webdriver/common/driver.rb:47:in `for'
from /app/vendor/bundle/ruby/3.1.0/gems/selenium-webdriver-4.7.1/lib/selenium/webdriver.rb:88:in `for'
from bin/flights_data.rb:22:in `scraper'
from bin/flights_data.rb:36:in `<main>'
I can't tell what the error means. I installed both the chromedriver buildpack and the the chrome buildpack. I have selenium listed in the gem file.
gem file
gem 'selenium-webdriver'
test ruby file
selenium
def selenium
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--headless')
driver = Selenium::WebDriver.for :chrome, options: options
puts "HELLO"
open_google(driver)
end
def open_google(driver)
driver.get 'https://www.google.com/flights'
end
```
Can someone help explain the error?
I needed to add the chrome driver add on Heroku and run restart server.

Pry on the production server - how can I make it work there?

I can debug an app locally with binding.pry just fine. But I need to that on the remote server (webiste) as well, because locally I don't have any error but on production I do. So put binding.pry in the source file on the server and when I made a post request to the website, I didn't return any response and even when I ran rails console on the server didn't change anything and there was no output in rails console.
It's a dev server, so it's visible in the internet but it's a developer server, although for rails it's production because RAIL_ENV is equal to production. I really need to debug it the way I can do locally using pry. How can I do it?
update:
# bundle exec pry-remote
/usr/lib/ruby/1.9.1/drb/drb.rb:736:in `rescue in block in open': druby://127.0.0.1:9876 - #<Errno::ECONNREFUSED: Connection refused - connect(2)> (DRb::DRbConnError)
from /usr/lib/ruby/1.9.1/drb/drb.rb:730:in `block in open'
from /usr/lib/ruby/1.9.1/drb/drb.rb:729:in `each'
from /usr/lib/ruby/1.9.1/drb/drb.rb:729:in `open'
from /usr/lib/ruby/1.9.1/drb/drb.rb:1191:in `initialize'
from /usr/lib/ruby/1.9.1/drb/drb.rb:1171:in `new'
from /usr/lib/ruby/1.9.1/drb/drb.rb:1171:in `open'
from /usr/lib/ruby/1.9.1/drb/drb.rb:1087:in `block in method_missing'
from /usr/lib/ruby/1.9.1/drb/drb.rb:1105:in `with_friend'
from /usr/lib/ruby/1.9.1/drb/drb.rb:1086:in `method_missing'
from /web/my_site.com/releases/201501271120/vendor/bundle/ruby/1.9.1/gems/pry-remote-0.1.8/lib/pry-remote.rb:289:in `run'
from /web/my_site.com/releases/201501271120/vendor/bundle/ruby/1.9.1/gems/pry-remote-0.1.8/bin/pry-remote:4:in `<top (required)>'
from /web/my_site.com/releases/201501271120/vendor/bundle/ruby/1.9.1/bin/pry-remote:19:in `load'
from /web/my_site.com/releases/201501271120/vendor/bundle/ruby/1.9.1/bin/pry-remote:19:in `<main>'
I assume your production app is run by some kind of daemonized application server, such as Puma or Unicorn.
In this setup, pry-remote can help.
add it to your Gemfile
use binding.remote_pry instead of binding.pry
execute bundle exec pry-remote on your server
You'll get a pry shell as soon as the breakpoint has been hit.

Capistrano : NoMethodError: undefined method `recv' for #<IO:fd XX>

This error in Capistrano (> 3) prevents me from deploying my Rails application. My Capistrano config works fine on another environment.
DEBUG [6c7d7bed] Command: if test ! -d /opt/my_app/releases/20140429175529; then echo "Directory does not exist '/opt/my_app/releases/20140429175529'" 1>&2; false; fi
cap aborted!
NoMethodError: undefined method `recv' for #<IO:fd 49>
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/net-ssh-2.8.0/lib/net/ssh/buffered_io.rb:65:in `fill'
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/net-ssh-2.8.0/lib/net/ssh/transport/packet_stream.rb:86:in `next_packet'
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/net-ssh-2.8.0/lib/net/ssh/transport/session.rb:178:in `block in poll_message'
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/net-ssh-2.8.0/lib/net/ssh/transport/session.rb:173:in `loop'
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/net-ssh-2.8.0/lib/net/ssh/transport/session.rb:173:in `poll_message'
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/net-ssh-2.8.0/lib/net/ssh/transport/session.rb:210:in `block in wait'
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/net-ssh-2.8.0/lib/net/ssh/transport/session.rb:208:in `loop'
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/net-ssh-2.8.0/lib/net/ssh/transport/session.rb:208:in `wait'
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/net-ssh-2.8.0/lib/net/ssh/transport/session.rb:87:in `initialize'
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/net-ssh-2.8.0/lib/net/ssh.rb:200:in `new'
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/net-ssh-2.8.0/lib/net/ssh.rb:200:in `start'
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/sshkit-1.4.0/lib/sshkit/backends/connection_pool.rb:24:in `create_or_reuse_connection'
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/sshkit-1.4.0/lib/sshkit/backends/netssh.rb:173:in `ssh'
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/sshkit-1.4.0/lib/sshkit/backends/netssh.rb:126:in `block in _execute'
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/sshkit-1.4.0/lib/sshkit/backends/netssh.rb:123:in `tap'
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/sshkit-1.4.0/lib/sshkit/backends/netssh.rb:123:in `_execute'
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/sshkit-1.4.0/lib/sshkit/backends/netssh.rb:66:in `execute'
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/sshkit-1.4.0/lib/sshkit/backends/abstract.rb:75:in `within'
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/capistrano-3.2.1/lib/capistrano/tasks/deploy.rake:207:in `block (3 levels) in <top (required)>'
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/sshkit-1.4.0/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/sshkit-1.4.0/lib/sshkit/backends/netssh.rb:54:in `run'
/Users/such/.rvm/gems/ruby-2.1.1#my_app/gems/sshkit-1.4.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => deploy:set_current_revision
(See full trace by running task with --trace)
The deploy has failed with an error: #<NoMethodError: undefined method `recv' for #<IO:fd 49>>
I'm using a proxy to connect to my remote servers (on both environment). SSH connection is working perfectly.
set :ssh_options, proxy: Net::SSH::Proxy::Command.new('ssh user#gateway -W %h:%p')
Has anyone ever experienced this issue?
Workaround
My weak understanding of the error is that after the ssh negotiation, sometimes the socket returned to net-ssh is a file descriptor which is unexpected.
I have added:
gem 'sshkit', github: 'msimonin/sshkit', branch: 'gateway'
to my Gemfile so that the ssh connection is only established once.
Related configuration is:
SSHKit.config.backend.configure do |ssh|
ssh.gateway = 'user#gateway'
end
It works fine this way. I can't wait for the pull request to be merged.
The connection objects are always a file descriptor-backed IO instance if you're using proxy commands. The code lives in lib/net/ssh/proxy/command.rb and it injects the recv method right after the bit that popens the pipes and waits for something to become readable, so I'm not sure why it sometimes fails (I've seen it too). Based on the callstack, I think it has returned already, so recv should be there.
Have you opened an issue?

Connection refused (PGError) (postgresql and rails)

I keep getting this error when i try to run my localhost using "$rails s":
(Mac OSX 10.8.3)
(ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0])
(Rails 3.2.11)
(psql (PostgreSQL) 9.2.2 ) **installed with homebrew
I have been doing a lot of uninstalling postgresql and reinstalling so I have a hunch that there may be conflicting libraries somewhere...i just dont know where to start.
I had Postgresql 9.1 and 9.2 in the same folder and just moved 9.1 into the trash.
Here is the output when I run "rails s" in the terminal
Danny$ rails s
^[b=> Booting Thin
=> Rails 3.2.11 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `initialize': could not connect to server: Connection refused (PGError)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5433?
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5433?
could not connect to server: Connection refused
Is the server running on host "localhost" (fe80::1) and accepting
TCP/IP connections on port 5433?
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `new'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `connect'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:326:in `initialize'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
from /Users/Danny/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
from /Users/Danny/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/model_schema.rb:308:in `clear_cache!'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/railtie.rb:97:in `block (2 levels) in <class:Railtie>'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:418:in `_run__3642716200177086041__prepare__4186317719333288752__callbacks'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:405:in `__run_callback'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/actionpack-3.2.11/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/actionpack-3.2.11/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `run'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `each'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/application.rb:136:in `initialize!'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/Danny/Dropbox/programming/coding/f_app/config/environment.rb:7:in `<top (required)>'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `block in require'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
from /Users/Danny/Dropbox/programming/coding/f_app/config.ru:3:in `block in <main>'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
from /Users/Danny/Dropbox/programming/coding/f_app/config.ru:in `new'
from /Users/Danny/Dropbox/programming/coding/f_app/config.ru:in `<main>'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.4.5/lib/rack/builder.rb:40:in `parse_file'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/commands/server.rb:46:in `app'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.4.5/lib/rack/server.rb:304:in `wrapped_app'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/commands/server.rb:70:in `start'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/commands.rb:55:in `block in <top (required)>'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/commands.rb:50:in `tap'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
The error message is instrumental:
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5433?
port
You may be trying to connect to the wrong port.
Standard port is 5432. Check how (and whether at all) you started your postgres server:
postgres#db:~$ ps -auxww | grep ^postgres
... <stripped more lines>
postgres 1274 0.0 0.3 1437240 57308 ? S May27 5:01 /usr/lib/postgresql/9.1/bin/postgres -D /var/lib/postgresql/9.1/main -c config_file=/etc/postgresql/9.1/main/postgresql.conf
The manual has related information here.
In my example, settings from /etc/postgresql/9.1/main/postgresql.conf got used, which says (among many other settings):
port = 5432
Or run:
netstat -nlp | grep postgres
Or just look here (at least in Debian or Ubuntu):
ls -lA /var/run/postgresql/
PostgreSQL picks the next free port if you create a new database cluster. Since you installed repeatedly, you may have confused port numbers.
listen_addresses
Or you just forgot to allow TCP/IP connections. Related answers:
Run batch file with psql command without password
What's the difference between "local" and "localhost" connection types in pg_hba.conf?
no pg_hba.conf entry for host
This may resolve the issue :-
Get the hba.conf file address by using command SHOW config_file; and SHOW hba_file; in sql prompt
Now open hba.conf and add this host all all 0.0.0.0/0 trust
Now open postgresql.conf and add listen_address = '*'
In my case, the problem was caused by the upgrade of postgresql-9.4 to postgresql-9.5 in Ubuntu 16.04. Since, There were two versions installed at some point in time, the later installed version i.e. postgresql-9.5's config changed to default port of 5433 (instead of standard default 5432).
The problem occurred when my Rails project tried to connect to the default port of postgresql (since the port was not defined explicitly defined in database.yml file) and kept failing. Even after removal of postgresql-9.4 later.
Solution changing postgresql's config file
The solution is changing the port in the configuration of updated postgresql (9.5). To do this open the file /etc/postgresql/9.5/main/postgresql.conf and change the line
port = 5433 # (change requires restart)
to
port = 5432 # (change requires restart)
and then restart the server with sudo service postgresql restart.
Solution with changing Rails' `database.yml' file
Alternatively, you can change rails' database.yml file by explicitly mention the new port (that ie 5433) without changing the postgresql's config file. To do this, simply add a line like this
port: 5433
and restart the rails server.
sudo -u postgres pg_ctlcluster 9.3 main stop
followed by
sudo -u postgres pg_ctlcluster 9.3 main restart
worked for me
I got this error message hooking up to Jira (from the Jira side) and the solution was to change the "Hostname or IP address of the database server." to "localhost". If you're running locally you can't just put in your local ip address.
Also the next issue for a local install is the password always fails even though that's correct because pg_hba.conf needs to be edited so the authentication method is "trust".
In postgresql.conf, /var/lib/pgsql/data/postgresql.conf :
change the listen_addresses = 'localhost' to listen_addresses = '*'
enable the default port as 5432, port = 5432
Also in pg_hba.conf, /var/lib/pgsql/data/pg_hba.conf,
try the authentication method as trust

Unitialized constant error in rails console vs. irb using a Mechanize wrapper

First question from a fundamental level - What is the meaning of an un-initialized constant error in Ruby? I come from an objective-c background, if that helps provide some context.
Secondly, I am running a rake task in rails that is throwing the aforementioned error. Specifically, the error occurs when I am using the 'tor-privoxy' gem, which is a Mechanize wrapper allowing automated browsing through a tor proxy.
I am using the following example code provided on github: https://github.com/pirj/tor-privoxy
agent ||= TorPrivoxy::Agent.new '127.0.0.1', '', {8118 => 9050} do |agent|
sleep 10
puts "New IP is #{agent.ip}"
page = agent.get('https://www.example.com/')
end
>> New IP is 72.141.125.115
>> NameError: uninitialized constant Net::HTTP::Persistent::SSLReuse::HTTPResponse
from /Library/Ruby/Gems/1.8/gems/net-http-persistent-2.3.3/lib/net/http/persistent/ssl_reuse.rb:115:in `connect'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:553:in `do_start'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:548:in `start'
from /Library/Ruby/Gems/1.8/gems/net-http-persistent-2.3.3/lib/net/http/persistent.rb:405:in `connection_for'
from /Library/Ruby/Gems/1.8/gems/net-http-persistent-2.3.3/lib/net/http/persistent.rb:616:in `request'
from /Library/Ruby/Gems/1.8/gems/mechanize-2.1/lib/mechanize/http/agent.rb:264:in `fetch'
from /Library/Ruby/Gems/1.8/gems/mechanize-2.1/lib/mechanize.rb:319:in `get'
from /Library/Ruby/Gems/1.8/gems/tor-privoxy-0.1.1/lib/tor-privoxy/agent.rb:16:in `send'
from /Library/Ruby/Gems/1.8/gems/tor-privoxy-0.1.1/lib/tor-privoxy/agent.rb:16:in `method_missing'
from (irb):4
from /Library/Ruby/Gems/1.8/gems/tor-privoxy-0.1.1/lib/tor-privoxy/agent.rb:11:in `call'
from /Library/Ruby/Gems/1.8/gems/tor-privoxy-0.1.1/lib/tor-privoxy/agent.rb:11:in `initialize'
from (irb):1:in `new'
from (irb):1
On the other hand, if I run this same code in irb, it does not throw the unitialized constant error. I have ensured that my gemfile includes 'tor-privoxy' and ran the 'bundle install' command.
if you want to work with ruby on your mac, i recommend that you use a tool like rvm or rbenv to manage your installation of ruby.
the error that you are experiencing seems to be already known. have a look at this github issue: https://github.com/thrillcall/net-http-persistent/commit/9f770b4660f1c9c433c1f3b50ba24dd4f1f71cf8

Resources