Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

URI::Fetch and LWP::UserAgent strangeness

by szabgab (Priest)
on Dec 30, 2012 at 19:20 UTC ( #1010955=perlquestion: print w/replies, xml ) Need Help??
szabgab has asked for the wisdom of the Perl Monks concerning the following question:

In the following example I keep getting "1: Forbidden" as output, but I don't see what is the real difference between the two calls. Can anyone see it? UIR::Fetch is at 0.09 and LWP::UserAgent is 6.04.
use strict; use warnings; use URI::Fetch; use LWP::UserAgent; my $source = ''; my $res2 = URI::Fetch->fetch($source); print '2: ' . URI::Fetch->errstr if not $res2; my $ua = LWP::UserAgent->new; $ua->env_proxy; # force allowing of proxies my $res1 = URI::Fetch->fetch($source, UserAgent => $ua); print '1: ' . URI::Fetch->errstr if not $res1;
If I change the $source to be then I keep getting "1: Bad Behavior".

Very strange. Other URLs I tried work well.

And just to explain why is this important, I am using XML::Feed to fetch and parse RSS and Atom feeds, and XML::Feed uses the code as it is written in the problematic case. So currently these two feeds keep giving me error.


I found it. I think. Earlier, when I stepped through the code with the debugger I missed it, but now I saw the difference. The LWP::UserAgent created by URI::Fetch identifies itself as "URI::Fetch/0.09" while the default UserAgent I passed to the fetch method had the default identification string 'libwww-perl/6.04'.

Apparently those two servers refuse to serve to the well known Perl user agent. Probably in an attempt to fend off certain bots.

So I have to change the UserAgent in XML::Feed.

Replies are listed 'Best First'.
Re: URI::Fetch and LWP::UserAgent strangeness
by Gryllida (Acolyte) on Jun 03, 2013 at 02:14 UTC
    How exactly do you do the "So I have to change the UserAgent in XML::Feed." thing?

      It looks like you actually have to edit the source code of

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1010955]
Approved by davido
Front-paged by Old_Gray_Bear
[choroba]: Most coffees? Depends on the country :-)
[choroba]: oh, you mean a cup with no water.
[Discipulus]: you are rigth, gory details but i remember from dunnowhere that concetrate caffein is more effective than brown water almost coffe..
[LanX]: prepared both kinds a 100 times and thinks the amount of grind code is about the same
Discipulus less effective i mean
[LanX]: (french press vs espresso cooker )
[LanX]: s/code/coffee/

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2017-01-16 10:57 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (148 votes). Check out past polls.