Failed to open TCP connection to :80 HTTParty gem
11,035
You have an excess symbol in your code:
class Recipe
# some code here
base_uri = "https://doesntmatter.com/api"
^ # the equal symbol is redundant.
# remove it and all will works as expected
# ....
end
Author by
Mihir Deshpande
Updated on June 14, 2022Comments
-
Mihir Deshpande about 2 years
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 'https://api.coursera.org/api/courses.v1' 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 = "https://doesntmatter.com/api" #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...