1

Am trying to get the user agent that is calling an API built with bottle micro framework. When the API is called directly using a browser, it shows what the user agent is. However, when its called from another application written e.g. in PHP or JAVA, it doesn't show the user agent.

I can however get the IP address whether or not the request is from browser or another application

client_ip = request.environ.get('REMOTE_ADDR') 
logging.info("Source IP Address: %s" %(client_ip)) #Works
browser_agent = request.environ.get('HTTP_USER_AGENT')
logging.info("Source Browser Type: %s" %(browser_agent)) #Doesn't work when called from an application

When I call it using a browser or say postman, it gives me the result as below:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.3

So, is there a special parameter to use to know what type of agent is calling the API?

lukik
  • 3,919
  • 6
  • 46
  • 89

1 Answers1

1

Clients are not required to send User-agent headers. Your browser is sending one (as most do), but your PHP and Java clients are (probably) not.

If you have control over the clients, add a user agent header to each request they make. For example, in PHP, see this SO answer.

Community
  • 1
  • 1
ron rothman
  • 17,348
  • 7
  • 41
  • 43