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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I'm writing a podcatcher and I ran into a problem where one particular podcast (whose RSS feed downloads fine in Firefox or wget) was failing to download when I used the default HTTP headers I used with all the other podcasts I've tested with. It would give a "406 Not Aceptable" error, which research suggested was caused by bad Accept headers. I ran wget -d to see what headers it was using and copied them into my script (or rather the config file for my script), and got the same error with this podcast. Below, find a simplified version of the code that reproduces the problem.

#! /usr/bin/perl use strict; use warnings; use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->agent('Mozilla/5.0'); $ua->show_progress( 1 ); my %headers = ( 'Accept' => '*/*', 'Accept-Encoding' => 'identity', 'Connection' => 'Keep-Alive', # 'Host' => '' ); 'Host' => '' ); #my $url = ''; my $url = ''; my $response = $ua->get( $url, %headers ); if ( $response->is_success ) { print "Okay!\n"; } else { my $status = $response->status_line; print "failed to download $url: $status\n"; }

If I use the commented out lines instead for the Host and $url value (checking a different podcast's RSS feed), everything works fine. I also tried using the default Firefox Accept: header, based on, and got the same 406 error. The same podcast also give me a 406 error when I try to get an individual mp3 file.

Any ideas how to narrow the problem down further, if not fix it?

I'm using Perl v5.26.1 and LWP::UserAgent version 6.31.

In reply to "406 not acceptable" errors with LWP::UserAgent::get by jimhenry

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2021-12-03 20:32 GMT
Find Nodes?
    Voting Booth?
    R or B?

    Results (30 votes). Check out past polls.