我正在尝试一个API请求,使用ruby从github上的公共仓库中获取标签。我有时会收到错误消息,而其他时候它会起作用。大多数情况下不会。
我遇到的错误:
C:/Ruby25/lib/ruby/2.5.0/net/http.rb:939:in `rescue in block in connect': Failed to open TCP connection to https://api.github.com/repos/puppetlabs/puppetlabs-stdlib/tags:80 (no implicit conversion of URI::HTTPS into String) (TypeError)
puts "INFO: Checking #{pupmod} new releases".green
require 'net/http'
require 'json'
require 'uri'
url = "#{$github_pubapi}/#{pupmod}/tags"
uri = URI.parse(url)
headers = {
'Authorization'=>'token df61c638274d9ca9e3ea663341f5af2bf122db08'
}
response = Net::HTTP.get(uri, headers)
parsed = JSON.parse(response)
latestRelease = parsed.first["name"]
puts latestRelease