Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

File does not exist: 500 read failed

by CColin (Scribe)
on Dec 07, 2007 at 13:43 UTC ( #655647=perlquestion: print w/ replies, xml ) Need Help??
CColin has asked for the wisdom of the Perl Monks concerning the following question:

Hi Am getting an intermittent error on a script calling an API service that has worked ok in the past - error message as follows:
Unsuccessful stat on filename containing newline at /usr/local/share/p +erl/5.8.8/XML/Simple.pm line 939. File does not exist: 500 read failed: [error relating to failure of line in program reproduced in snippet be +low]
The context is where the subroutine calling the API service fails (using XML::Simple to parse the returned object
my $response = $userAgent->request($request); my $som=$response->{'_content'}; #print Dumper(\$som); my $result = XMLin($som); # Line where failure occurs.
I'm assuming if the sub XMLin failed that the file was not found? However, I'm not familiar with what the error message means exactly, tried googling didn't get far. What should I do to get to the bottom of this? Also, at the moment the program crashes out if the error is encountered. Any tips on catching this particular error and continuing appreciated. Thanks Colin

Comment on File does not exist: 500 read failed
Select or Download Code
Re: File does not exist: 500 read failed
by plobsing (Friar) on Dec 07, 2007 at 14:01 UTC
    Looks like your useragent response was
    500 read failed: [error relating to failure of line in program reproduced in snippet be +low]
    You should validate responses before trying to parse it as XML (it notices its not XML and thinks its a filename). Or you could look at this XML::Simple(ERROR_HANDLING)
      Ok - Thanks; the question then is what to do about the 500 read failed: message if that is the cause of all the trouble - what does it mean? Colin
        Depends on what protocol you are using.
        If its HTTP (and what isn't these days?), then there's been an "internal server error". Perhaps the webservice you are trying to use has a bug. Perhaps you are sending it bad data and its not catching it until it makes thinks mess up.
        In any case HTTP 500 means that theres an error on the other end. Maybe you should have a second look at the API.
Re: File does not exist: 500 read failed
by Herkum (Parson) on Dec 07, 2007 at 16:45 UTC
    Unsuccessful stat on filename containing newline...

    This means that the XML::Simple module is taking your $som variable and assumes that it is a file path because it is invalid XML.

    You need to validate the data that receive from the API service. A simple solution would be,

    use English qw( -no_match_vars ); my $result; eval { $result = XMLin($som); } if ($EVAL_ERROR) { die "Invalid XML retrieved. The error was " . $EVAL_ERROR . "\n"; }

    Also don't refer to internal values for a object ESPECIALLY when it already has an interface!

    ## GOOD my $som=$response->content; ## BAD!!! my $som=$response->{'_content'};
      Thanks. Speed is of the essence on this service, will using "eval" put any sort of time overhead on the function? Colin

        Inappropriately named eval BLOCK is very different from eval EXPR.
        eval EXPR invokes the Perl parser to parse and execute EXPR. This should be avoided whenever possible.
        eval BLOCK, the function used in the parent, is the benign construct known as try in other languages.

        See eval.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2014-07-14 07:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (255 votes), past polls