Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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 = 'http://thorsen.pm/atom'; 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 http://code.foo.no/feed 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.

Update

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.


In reply to URI::Fetch and LWP::UserAgent strangeness by szabgab

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (9)
    As of 2015-07-29 23:32 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (269 votes), past polls