selwin / python-user-agents

A Python library that provides an easy way to identify devices like mobile phones, tablets and their capabilities by parsing (browser) user agent strings.
MIT License
1.43k stars 196 forks source link

Getting different parsed user agent on same machine #102

Open SeanWhipple opened 4 years ago

SeanWhipple commented 4 years ago

I have two python virtual environments that are installed on the same Mac. And when I try to parse a user agent one virtual environment is giving a different answer than the other. While the envs are not exactly the same I'm surprised to see these outputs.

One environment gives the following (attached requirements file r1)

In [1]: import user_agents

In [2]: user_agent_str = (
   ...:             "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 ("
   ...:             "KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36"
   ...:         )

In [3]: user_agents.parse(user_agent_str).device
Out[3]: Device(family='Other', brand=None, model=None)

The second environment gives (requirements file r2)

>>> import user_agents
>>> user_agent_str = (
...             "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 ("
...             "KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36"
...         )
>>> user_agents.parse(user_agent_str).device
Device(family='Mac', brand='Apple', model='Mac')
>>>

The two requirements files are attached for debugging. Both python environments are running 3.7.4

requirements_files.zip

gil9red commented 3 years ago

It is not python-user-agents that parses the string, but uap-python. I think if you parse the string through it, you will see the difference in it for the two environments

from ua_parser import user_agent_parser
import pprint

user_agent_str = (
    ...
)

parsed_string = user_agent_parser.Parse(ua_string)
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(parsed_string)