Failed to open TCP connection to :80 HTTParty gem

So in my course on Coursera I'm required to build this rather simple aplication to obtain and display an array from an external api. I'm using the ruby on rails framework. (I'm using windows 10)

Controller -

class CoursesController < ApplicationController def index @search_term = params[:looking_for] || 'jhu' @courses = Coursera.for(@search_term) end end 

Model

class Coursera include HTTParty default_options.update(verify: false) # Turn off SSL verification base_uri ' default_params fields: "photoUrl,description",q: "search" format :json def self.for term get("",query: {query: term}) ["elements"] end end 

The view is irrelevant as this works fine. But in my other app , I get this error -

Errno::ECONNREFUSED: Failed to open TCP connection to :80 (Connection refused - connect(2) for nil port 80) 

This is the other app which I'm having the problem with -

Controller -

class RecipesController < ApplicationController def index @search_term = params[:search] || 'chocolate' @recipes = Recipe.for @search_term end end 

Model -

class Recipe include HTTParty default_options.update(verify: false) # Turn off SSL verification key_value = ENV['FOOD2FORK_KEY'] hostport = ENV['FOOD2FORK_SERVER_AND_PORT'] || 'food2fork.com' base_uri = "" #website mentioned here #doesn't matter , I get the error nonetheless default_params key: ENV['FOOD2FORK_KEY'] ,q: "search" format :json def self.for term get("/search",query: {query: term}) ["recipes"] end end 

I've tried disabling all possible firewalls , unblocked all ports with TCP in windows firewall , but I still get the same error. Any ideas how to fix this ? Because I don't think its a problem in my code yet...

1

1 Answer

You have an excess symbol in your code:

class Recipe # some code here base_uri = "" ^ # the equal symbol is redundant. # remove it and all will works as expected # .... end 
3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like