无法下载文件,错误500

时间:2015-09-30 21:28:01

标签: ruby amazon-web-services amazon-s3

我正在尝试从Amazon Datafeed网址下载压缩文件,然后将其解压缩。

这是我的代码:

    open('public/files/amazon_ce.xml', 'w') do |local_file|
      open('https://assoc-datafeeds-eu.amazon.com/datafeed/it_amazon_ce.xml.gz', :http_basic_authentication=>[USERNAME, PASSWORD]) do |remote_file|
        local_file.write(Zlib::GzipReader.new(remote_file).read)
      end
    end

如果我尝试使用其他文件,一切正常,但不能使用此Amazon文件:错误是:

OpenURI::HTTPError: 500 Internal Server Error

我在使用浏览器下载相同文件时记录了请求...

GET /datafeed/getFeed?filename=it_amazon_ce.xml.gz HTTP/1.1
Host: assoc-datafeeds-eu.amazon.com:443
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate, sdch
Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4
Cookie: xxxxx
Referer: https://assoc-datafeeds-eu.amazon.com/datafeed/listFeeds?format=text/html
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36

HTTP/1.1 302 Moved Temporarily
Cache-Control: no-cache
Content-Length: 0
Date: Wed, 30 Sep 2015 21:24:22 GMT
Expires: Thu, 01 Jan 1970 00:00:00 UTC
Location: http://prod-deamazon.outputs.datafeeds.s3.amazonaws.com/it_amazon_dvd.xml.gz?Signature=xxxx&AWSAccessKeyId=xxxx&Expires=xxxx
Pragma: No-cache
Server: Apache-Coyote/1.1

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您的浏览器已经过身份验证,并且有一个允许您下载文件的Cookie。

您需要确保您的Rails应用程序具有正确的凭据才能下载文件(我无法在浏览器中查询用户名/密码)