views:

23

answers:

2

how do i change my headers and request so that i appear as firefox ...

like when request to some servers

import urllib
f = urllib.urlopen("rss feed")

they deny my request saying your client dosent have permission...

i get reply but the reply contains " your client dosent have permission"

so how do i get around this and get the data...

+1  A: 

If you want to use good old urllib instead of newer, fancier urllib2, then as urllib's docs say, and I quote,

For example, applications may want to specify a different User-Agent header than URLopener defines. This can be accomplished with the following code:

import urllib

class AppURLopener(urllib.FancyURLopener):
    version = "App/1.7"

urllib._urlopener = AppURLopener()

Of course, you'll want a version (aka User-Agent header) suitable for whatever version of Firefox (or w/ever else;-) you want to pretend you are;-).

Alex Martelli