[英]HTTP::ConnectionError & Errno::EHOSTUNREACH Errors in Rails App
I'm working on a Rails app and here are two important pieces of the error message I get when I try to seed data in my database: 我正在使用Rails应用程序,这是我尝试在数据库中播种数据时收到的两个重要错误消息:
HTTP::ConnectionError: failed to connect: Operation timed out - SSL_connect HTTP :: ConnectionError:连接失败:操作超时-SSL_connect
Errno::ETIMEDOUT: Operation timed out - SSL_connect Errno :: ETIMEDOUT:操作超时-SSL_connect
Here is my code, where I'm pulling data from a file, and creating Politician objects: 这是我的代码,在这里我从文件中提取数据并创建Politician对象:
politician_data.each do |politician|
photo_from_congress = "https://theunitedstates.io/images/congress/original/" + politician["id"]["bioguide"] + ".jpg"
HTTP.get(photo_from_congress).code == 200 ? image = photo_from_congress : image = "noPoliticianImage.png"
Politician.create(
name: "#{politician["name"]["first"]} #{politician["name"]["last"]}",
image: image
)
end
I put in a pry, and the iteration works for the first loop, so the code is OK. 我撬了一下,迭代在第一个循环中起作用,因此代码正常。 After several seconds, the loop breaks, and I get that error, so I think it has something to do with the number of HTTP.get requests I'm making?
几秒钟后,循环中断,并且出现该错误,所以我认为这与我发出的HTTP.get请求数量有关?
https://github.com/unitedstates/images is a Git repo. https://github.com/unitedstates/images是一个Git仓库。 Perhaps that repo can't handle that many get requests?
也许那个仓库不能处理那么多的获取请求?
I did some Google'ing and saw it may have something to do with "Request timed out" error? 我做了一些Googleinging,发现它可能与“请求超时”错误有关? My having to set up a proxy servers?
我必须设置代理服务器吗? I'm a junior programmer so please be very specific when responding.
我是一名初级程序员,因此在回复时请非常具体。
*EDIT TO ADD THIS : *编辑添加此内容 :
I found this blurb on the site where I'm making get requests to cull photos ( https://github.com/unitedstates/images ), that may help? 我在正在请求删除照片的网站( https://github.com/unitedstates/images )上发现了这个问题,这可能会有所帮助吗?
Note: Our HTTPS permalinks are provided through CloudFlare's Universal SSL, which also uses "Flexible SSL" to talk to GitHub Pages' unencrypted endpoints. 注意:我们的HTTPS永久链接是通过CloudFlare的通用SSL提供的,该通用SSL还使用“ Flexible SSL”与GitHub Pages的未加密端点进行对话。 So, you should know that it's not an end-to-end encrypted channel, but is encrypted between your client use and CloudFlare's servers (which at least should dissociate your requests from client IP addresses).
因此,您应该知道这不是一个端到端的加密通道,而是在客户端使用和CloudFlare服务器之间加密的(至少应该将您的请求与客户端IP地址分离)。
by the way, using "Net::HTTP" instead of the "HTTP" Ruby gem worked. 顺便说一句,使用“ Net :: HTTP”而不是“ HTTP” Ruby gem可以正常工作。 Instead of checking the status code, i just checked to see if the body contained key text:
我没有检查状态码,而是检查主体是否包含关键文本:
photo_from_congress = "https://theunitedstates.io/images/congress/original/" + politician["id"]["bioguide"] + ".jpg"
photo_as_URI = URI(photo_from_congress)
Net::HTTP.get_response(photo_as_URI ).body.include?("File not found") ? image = "noPoliticianImage.png" : image = photo_from_congress
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.