mercredi 30 septembre 2015

Ruby, can't download a file, error 500

I'm trying to download a zipped file from Amazon Datafeed url and then decompress it.

This is my code:

    open('public/files/amazon_ce.xml', 'w') do |local_file|
      open('http://ift.tt/1OH7ym2', :http_basic_authentication=>[USERNAME, PASSWORD]) do |remote_file|
        local_file.write(Zlib::GzipReader.new(remote_file).read)
      end
    end

If I try with another file everything is ok, but not with this Amazon file: the error is:

OpenURI::HTTPError: 500 Internal Server Error

I logged the request when I download the same file using the browser...

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: http://ift.tt/1GidfyT
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://ift.tt/1OH7wdX
Pragma: No-cache
Server: Apache-Coyote/1.1

Any idea?




1 commentaire: