Get user browser info in Python Bottle
python, user-agent
Solution
Thank you everyone for your answers, I found something really simple that works.
Download httpagentparser module from: https://pypi.python.org/pypi/httpagentparser
after that, just import it in your pythong program
import httpagentparser
Then you can write a function like this that returns browser, works like a charm:
def detectBrowser(request):
agent = request.environ.get('HTTP_USER_AGENT')
browser = httpagentparser.detect(agent)
if not browser:
browser = agent.split('/')[0]
else:
browser = browser['browser']['name']
return browser
That's it
Problem
I'm trying to find out which browsers are my users using and I'm running into a problem. If I try to read header "User-Agent" it usually gives me lots of text, and tells me nothing. For example, if I visit the site with Chrome, in "User-Agent" header there is: User-Agent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36". As you can see, this tells me nothing since there is mention of Mozzila, Safari, Chrome etc.. even though I visited with Chrome. Framework I've been using is Bottle (Python). Any help would be appreciated, thanks.