Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

How can I get images from urls - Getting 443 and 500 errors

by kevyt (Scribe)
on Mar 20, 2015 at 17:26 UTC ( [id://1120778]=perlquestion: print w/replies, xml ) Need Help??

kevyt has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to get catalog images from but I'm not having much luck. The current code displays 500 and 433 errors. Does anyone know how I may get images from the urls below? Thanks.

https://mms.image.mckesson.com/CumulusWeb/Images/High_Res/49176.jpg
https://mms.image.mckesson.com/CumulusWeb/Images/High_Res/803186.jpg
use warnings; use strict; # use Image::Grab; use LWP::Simple; open (IN, '< McKesson_Items_test.csv') or die ("Can't open the input f +ile $!"); while (<IN>){ chomp; my($item_number, $sku, $desc) = split /\,/; #print $item_number, $sku; my $url = 'https://mms.image.mckesson.com/CumulusWeb/Images/High_R +es/' . $sku . '.jpg'; #my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 } +); #my $req = HTTP::Request->new("GET", $url); #my $rep = $ua->request($req); #print $rep->status_line; use LWP 5.64; my $browser = LWP::UserAgent->new; my $response = $browser->get($url); die "Error at $url\n ", $response->status_line, "\n Aborting" unless $response->is_success; print "Whee, it worked! I got that ", $response->content_type, " document!\n"; #my $path = 'Images\\' . $item_number . '.jpg'; #my $path = $item_number . '.jpg'; #print " $url, $path\n"; #getstore($url, $path) or die "Can't download: $@\n"; }

Replies are listed 'Best First'.
Re: How can I get images from urls - Getting 443 and 500 errors
by hippo (Bishop) on Mar 20, 2015 at 17:43 UTC

    Version 5.64 of LWP is over 13 years old. Which version are you actually using? And why use both LWP and LWP::Simple? This example works fine for me (using LWP 6.02):

    use strict; use warnings; use LWP; my $sku = 49176; my $url = "https://mms.image.mckesson.com/CumulusWeb/Images/High_Res/$ +sku.jpg"; my $ua = LWP::UserAgent->new; my $resp = $ua->get($url); print $resp->code;
      I thought I replied but I don't see it. This worked on Linux. Thank you.
      use strict; use warnings; use LWP; use LWP::Simple; my $sku = 49176; my $url = "https://mms.image.mckesson.com/CumulusWeb/Images/High_Res/$ +sku.jpg"; my $ua = LWP::UserAgent->new; my $resp = $ua->get($url); print $resp->code; my $path = '../data_files/' .$sku . '.jpg'; getstore($url, $path ) or die "Can't download: $@\n"
      I have not used perl for a while and I used code that I found online for getting images. I'm using windows and I'm behind a firewall. I'll try your code from Linux without the firewall to see if that makes a difference. Thanks.
Re: How can I get images from urls - Getting 443 and 500 errors
by kevyt (Scribe) on Mar 20, 2015 at 17:35 UTC
    This gives a 500 error.
    #!/usr/bin/perl -w use strict; use warnings; use LWP::Simple; my $filename = "image.jpg"; unlink($filename); my $response = getstore("https://mms.image.mckesson.com/CumulusWeb/Ima +ges/High_Res/803186.jpg", $filename); print $response;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1120778]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-25 06:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found