[Tutor] user agent

Alan Gauld alan.gauld at btinternet.com
Thu Sep 25 01:55:41 CEST 2008


"jeremiah" <jeremiah.jester at panasonic.aero> wrote 

> I'm trying to force the user agent in a python login script... 

Might I ask why?
It should never be necessary and is extremely user hostile.
Especially given that many modern browsers are capable 
of emulating the troublesome ones - ie IE! And future versions 
might change the rules and you then have a huge maintenance 
overhead of keeping your list of browsers updated.

If at all possible it's better to put the effort into making your 
code browser neutral. Which mainly meams avoiding unusual 
HTML constructs, using ECMAscript rather than any vendor 
specific variant of JavaScript and not trying to control layout 
and style too closely (that's what PDF is for!)

> question is what are the possible user agents I can specify 

Thats a changing question because the number of browsers 
and what they report to the server is changing constantly.
Its usually more common to simply specify a small subset
of the most common ones and anyone with the audacity to 
prefer an alternative hgets a more or less rude message 
telling them to pick another browser....

> print the user agent at the end of the script so I know that it was
> accurately saved. Here is the first bit of my code.

Its stored in an environment variable. How you access that 
will depend on your server/framework but as a last resort 
os.getenv() should work.

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld




More information about the Tutor mailing list