ruby 在拯救302时,迭代列表不起作用

vd2z7a6w  于 12个月前  发布在  Ruby
关注(0)|答案(1)|浏览(109)

当我遍历一个列表时,对每个元素发送一个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的授权令牌?)

相关问题