无法打开到 :80 HTTParty gem 的 TCP 连接
Failed to open TCP connection to :80 HTTParty gem
所以在我的 Coursera 课程中,我需要构建这个相当简单的应用程序来从外部获取和显示数组 api。我在 rails 框架上使用 ruby。 (我正在使用 windows 10)
控制器-
class CoursesController < ApplicationController
def index
@search_term = params[:looking_for] || 'jhu'
@courses = Coursera.for(@search_term)
end
end
型号
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
该视图无关紧要,因为它工作正常。
但在我的其他应用程序中,出现此错误 -
Errno::ECONNREFUSED: Failed to open TCP connection to :80 (Connection refused - connect(2) for nil port 80)
这是我遇到问题的另一个应用程序 -
控制器 -
class RecipesController < ApplicationController
def index
@search_term = params[:search] || 'chocolate'
@recipes = Recipe.for @search_term
end
end
型号 -
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
我试过禁用所有可能的防火墙,在 windows 防火墙中使用 TCP 取消阻止所有端口,但我仍然遇到同样的错误。任何想法如何解决这一问题 ?因为我认为我的代码还没有问题...
您的代码中有多余的符号:
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
所以在我的 Coursera 课程中,我需要构建这个相当简单的应用程序来从外部获取和显示数组 api。我在 rails 框架上使用 ruby。 (我正在使用 windows 10)
控制器-
class CoursesController < ApplicationController
def index
@search_term = params[:looking_for] || 'jhu'
@courses = Coursera.for(@search_term)
end
end
型号
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
该视图无关紧要,因为它工作正常。 但在我的其他应用程序中,出现此错误 -
Errno::ECONNREFUSED: Failed to open TCP connection to :80 (Connection refused - connect(2) for nil port 80)
这是我遇到问题的另一个应用程序 -
控制器 -
class RecipesController < ApplicationController
def index
@search_term = params[:search] || 'chocolate'
@recipes = Recipe.for @search_term
end
end
型号 -
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
我试过禁用所有可能的防火墙,在 windows 防火墙中使用 TCP 取消阻止所有端口,但我仍然遇到同样的错误。任何想法如何解决这一问题 ?因为我认为我的代码还没有问题...
您的代码中有多余的符号:
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