Search code examples
perldownloadlwp

File download via LWP returns error 500 (probably timeout due to long waiting time)


I'm pretty new to Perl and just tried to use a simple and small script to download a file. It works on most websites, but it seems like it is not working on the one particular website I need to download a file from.

My code is:

use LWP::Simple;

my $status = getstore("http://www.regelleistung.net/download/ABGERUFENE_MRL_BETR_SOLL-WERTE.CSV", "file.csv");

if ( is_success($status) )
{
  print "file downloaded correctly\n";
}
else
{
  print "error downloading file: $status\n";
}

I always keep getting error status 500. The file is directly linked on https://www.regelleistung.net/ext/data/ where you can click on "MRL", "SRL" and "RZ_SALDO".

Also, if I try to download the file via clicking the link in my browser it takes like forever to load before the actual download starts.

I feel like I need getstore() to wait until either it timeouts (say ~60 seconds) or the file is loaded.

Do you have any hint that could help me solve this problem? Using some other library or method? Even keyworks might be helpful, since I actually don't know what I could search for on Google.


Solution

  • Your code ran successfully the first time I tried it. I suspect that the site may have been busy when you first tested

    To make the kind of changes that you are asking about you need the full LWP::UserAgent module, but I think your code should work for you if you keep trying a few times