lmocsi
lmocsi

Reputation: 1086

"Non-blocking socket operation" error in LWP::UserAgent package of Perl


The below code produces an error on Windows 7 Pro, it reads 5-8K bytes of the web page, then terminates:

use strict;
use LWP::UserAgent;
my $url = 'https://www.flickr.com/photos/71475421@N02/26176178323/';
my $ua = LWP::UserAgent->new;
my $res = $ua->get($url);
print $res->headers->as_string;

The error is:

X-Died: read failed: A non-blocking socket operation could not be 
completed immediately. at C:/Perl/lib/LWP/Protocol/http.pm line 467.

OS: Win 7 Pro (64bit)
Perl: 5.20.1 (32bit)
LWP: 6.08
LWP-Protocols-https: 6.06

Any ideas why is it not working, and how it can be fixed?

Thanks.

Upvotes: 1

Views: 558

Answers (2)

lmocsi
lmocsi

Reputation: 1086

ActivePerl itself (with its outdated LWP package) seems to be the culprit.
Switched to Strawberry Perl and it works like charm.
Dumping ActivePerl...

Upvotes: 0

Steffen Ullrich
Steffen Ullrich

Reputation: 123260

This problem is probably due to checking only against EAGAIN and not EWOULDBLOCK. These error codes are both the same on most UNIX but are different on Windows. I recommend to use a newer version of LWP (at least version 6.09) because there it explicitly deals with this issue and checks for both conditions.

Upvotes: 1

Related Questions