Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

A non-blocking socket operation could not be completed ?

by slugger415 (Monk)
on May 16, 2016 at 22:29 UTC ( [id://1163172]=perlquestion: print w/replies, xml ) Need Help??

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

Hi all, I've been using a Perl script for a couple of years to retrieve FaceBook event listings. It's worked fine until the last couple of months, and I'm very often getting this message:

Status read failed: A non-blocking socket operation could not be completed immediately. at C:/Strawberry/perl/vendor/lib/Net/HTTP/Methods.pm line 276.

I've searched around and couldn't find anything that explains what this means or what to do about it. Oddly, once in a while the script still works.

Here's a bit of my login code. I'm running on Windows 7 with Strawberry Perl v5.20.2.

use CGI; use File::Basename; use LWP::UserAgent; use strict; my %postLoginData; #necessary post data for login $postLoginData{'email'}=$email; $postLoginData{'pass'}=$password; $postLoginData{'persistent'}=1; $postLoginData{'login'}='Login'; our $response; #holds the response the HTTP requests #set the headers, let's make this a Firefox browser! our @header = ('Referer'=>'http://www.facebook.com', 'User-Agent'=>$us +er_agent); our $cookie_jar = HTTP::Cookies->new(file=>'fbkCookies.dat',autosave=> +1, ignore_discard=>1); our $browser = LWP::UserAgent->new; #init browser $browser->cookie_jar($cookie_jar); print " getting fb login...\n"; $browser->get('http://www.facebook.com/login.php',@header); print " posting login request...\n"; #here we actually login! $response = $browser->post('https://login.facebook.com/login.php',\%po +stLoginData,@header); #was login successful? if($response->content =~ /Incorrect Email/) { print "Login Failed...Quitting..\n"; exit; } else { print "..and we are in!\n\n"; #let's go to the homepage my $pageresponse = $browser->get( $url ,@header); # this is where the error appears: print $$pageresponse{_content};

I know there are FB modules out there that probably work better, but I'd like to understand what's happening here, if anyone has seen it before. Many thanks!

Replies are listed 'Best First'.
Re: A non-blocking socket operation could not be completed ?
by BrowserUk (Patriarch) on May 16, 2016 at 23:15 UTC

    As line 276 of HTTP::Methods on CPAN is a comment, you're probably down-level, so upgrading LWP might fix you up.

    The error message usually mean that the systems call has return EAGAIN, and needs to be retried. And that fits with the code nearby on CPAN:

    ## 276 # consume all incoming bytes while(1) { my $bytes_read = $self->sysread($_, 1024, length); if(defined $bytes_read) { $new_bytes += $bytes_read; last if $bytes_read < 1024; } elsif($!{EINTR} || $!{EAGAIN} || $!{EWOULDBLOCK}) +{ redo READ; } ...

    Doesn't explain why it would suddenly start failing now ... but worth a look.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Nit: It's EWOULDBLOCK, not EAGAIN.
      >perl -MErrno=EAGAIN,EWOULDBLOCK -E"say $!=$_ for EAGAIN,EWOULDBLOCK" Resource temporarily unavailable A non-blocking socket operation could not be completed immediately.

      I don't know why the socket would have been made non-blocking (assuming the message isn't misleading).

      Interesting - I updated Net::HTTP:Methods and LWP::UserAgent. I couldn't see any difference in the files, but the script seems to be working consistently now.

      Fingers x'd - thank you!

Re: A non-blocking socket operation could not be completed ?
by Marshall (Canon) on May 16, 2016 at 22:45 UTC
    I am curious as to the use of "our" instead of "my". Why did you do that? "our" puts a var in to the global symbol table. Who else is mucking with these "our" variables and why? The main reason to create an "our" variable is so that some other module can muck with it by name. All "my" vars are private.
        I apologize for getting off topic. Sounds like you have your problem solved with an LWP upgrade. But since we are already there...

        You can read more about "our" at our variables.

        If you "clobber" an "our" variable, you get a warnings, but it is still there and accessible with the full name. See demo code below. To declare a variable before use, "my" is almost always the "right answer", even with getopts.

        A "my" variable is completely "private" and cannot be accessed except in the scope and package in which it is declared. An "our" variable gets put into the package's symbol table and can be accessed by a different compilation unit, if the full name is used or if it is "exported" and "imported" by another package.

        #!usr/bin/perl use warnings; use strict; our $x = 99; my $x = 4; print "lexical my version of x=$x\n"; print "package version of x=$main::x"; __END__ "my" variable $x masks earlier declaration in same scope at C:\testing +\ourdemo.pl line 6. lexical my version of x=4 package version of x=99

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 00:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found