当我遍历一个列表时,对每个元素发送一个get请求,rescue中的block只在第一次迭代时执行。代码如下:
def download_doc(gem_id)
url = @base_url + ATTACHMENT_ENDPOINT + gem_id + "/attachment"
headers = {
'Authorization' => @token
}
attempts = 0
begin
response = RestClient::Request.execute(
method: :get,
url: url,
headers: { Authorization: "Bearer #{@token}" },
max_redirects: 0
)
rescue RestClient::Found => found
puts "FOUND #{gem_id}"
exec "wget \"#{found.response.headers[:location]}\" -O \"#{gem_id}.pdf\" -q --show-progress"
rescue => ex
puts ex.response
end
end
ids = File.read(@input_file).split(",")
arra.each do |id|
download_doc(id)
end
上下文是我做的GET请求,重定向到S3并抛出Only one auth mechanism allowed; only the X-Amz-Algorithm query parameter, Signature query string parameter or the Authorization header should be specified
错误。所以我停止了重定向,并尝试从初始GET请求中获取位置。
我尝试了多种不同的方法,调整救援块等。但却找不到解决办法。
我最好绕过S3错误(我想我应该以某种方式删除重定向RQ的授权令牌?)
1条答案
按热度按时间u0njafvf1#
问题是
exec
会停止脚本。使用反引号`代替。更多信息:https://rubyquicktips.com/post/5862861056/execute-shell-commands