joshfrench / rakismet

Easy Akismet and TypePad AntiSpam integration for Rails
MIT License
355 stars 46 forks source link

SocketError (getaddrinfo: nodename nor servname provided, or not known): #25

Closed genlighten closed 10 years ago

genlighten commented 11 years ago

Hi Josh:

I'm trying to implement Rakismet 0.4.2 in my Rails 2.3.14 app. I'm getting the following error after clicking "submit request" from my offerings#show view, the page from which our clients submit ProjectRequests (analogous to a blog_post view from which readers would submit comments):

SocketError (getaddrinfo: nodename nor servname provided, or not known): /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:in initialize' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:inopen' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:in connect' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:53:intimeout' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:93:in timeout' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:560:inconnect' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:553:in do_start' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:542:instart' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:440:in start' rakismet (0.4.2) lib/rakismet.rb:39:inakismet_call' rakismet (0.4.2) lib/rakismet/model.rb:45:in spam?' app/models/project_request.rb:59:incheck_for_spam' app/controllers/users/project_requests_controller.rb:26:in `create' ....

I'm running the app on my development server (http://localhost:3000). I'm connected to the Internet.

I've got the following in my ProjectRequest.rb model:


    class ProjectRequest < ActiveRecord::Base

    include AccountingMethods
    include CurrencyMethods
    include Rakismet::Model

    attr_accessible :title, :details, :budget, :provider_id, :offering_id, :offering_quantity, :request_type_id,
                    :accepted_date, :declined_date, :cancelled_date, :archived_by_user, :archived_by_provider, :workflow_state

    validates_presence_of :title, :details, :request_type_id
    validates_presence_of :budget, :if => :is_hourly?
    validates_numericality_of :budget_number, :greater_than_or_equal_to => 1, :if => :is_hourly?,
                              :message => "must be at least 0.01."

    has_one :project
    has_one :payable_item
    belongs_to :user
    belongs_to :provider
    belongs_to :offering
    belongs_to :offering_type, :foreign_key => :request_type_id

    before_create :check_for_spam

    def author
      self.user.login || "John Smith"
    end

    def author_email
      self.user.email || "example@example.com"
    end

    def comment_type
      "project_request"
    end

    def content
      self.title + ' ' + self.details
    end

    def permalink
      base = 'http://www.genlighten.com'
      if self.offering_id
        offering_title = self.offering.title.slugorize
        base + '/offerings/' + offering_title
      else
        provider_login = self.provider.login
        base + '/provider_profiles/' + provider_login
      end
    end

# following two methods from Ryan Bates' Railscast #65 "Stopping Spam with Akismet"
    def request=(request)
      self.user_ip     = request.remote_ip
      self.user_agent  = request.env['HTTP_USER_AGENT']
      self.referrer    = request.env['HTTP_REFERER']
    end

    def check_for_spam
      self.akismet_approved = !self.spam?
      puts "akismet response = #{self.akismet_response}"
      true
    end```

And the following snippet comes from the top of my project_requests_controller.rb: (the if @project_request.save line is line 26 in the error message above). This controller processes creation of a project request when the user clicks "submit request" on the offerings#show request submission form.

```Ruby/Rails
class Users::ProjectRequestsController < ApplicationController

    include UserMethods
    include CartMethods
    include ProjectRequestMethods
    include ProviderMethods

    layout 'new_default'

    before_filter :login_required
    before_filter :get_user_from_user_id
    before_filter :check_user_access
    before_filter :recover_cart, :only => :update
    before_filter :get_project_request, :only => [ :convert, :show, :update ]
    before_filter :get_offering_from_offering_id, :only => [ :create ]
    before_filter :get_provider_for_project_request, :only => :show
    before_filter :get_provider_from_provider_id, :only => [ :create ]
    before_filter :get_project_for_project_request, :only => [ :show, :update ]

    helper_method :sort_column, :sort_direction

    def create
      @project_request = @user.project_requests.build(params[:project_request])
      @project_request.request = request
      if @project_request.save
        if @project_request.akismet_approved?
          redirect_to convert_user_project_request_path(@user,@project_request)
        else
          # email admin that we've received a spam project_request
          flash[:error] = "We were unable to submit your request. Please contact Genlighten Support at (302)566-5871."
          redirect_to root_path
        end
      else
        flash[:error] = "Failed to submit your request #{@project_request.title}."
        get_offering_for_project_request
        @page_title = "#{@offering.title} | Genlighten"
        get_provider_for_project_request
        get_provider_feedback_summary
        render 'offerings/show'
      end    
    end```

And my config/initializers/rakismet.rb file contains these lines:

Rakismet::KEY = GlobalConfig.rakismet_key
Rakismet::URL = GlobalConfig.rakismet_url
Rakismet::HOST = GlobalConfig.rakismet_host

while my global_config.yml file contains the following:

  # Key and url for use with rakismet gem and Akismet anti-spam API access
  rakismet_key: 'my_akismet_key'
  rakismet_url: 'http://www.genlighten.com'
  rakismet_host: 'http://akismet.com/'

Can you offer any advice or suggestions? I'm guessing I haven't given rakismet the right parameters to find akismet to process the API there?

Thanks very much!

Dean Richardson (still a Rails novice, obviously)
Genlighten.com
WilliamDenniss commented 11 years ago

Looks like a network issue.

I turned off my wifi connection, ran "comment.spam?" and got the same error SocketError: getaddrinfo: nodename nor servname provided, or not known