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

Android 9 os version empty #92

Closed ardaguclu closed 4 years ago

ardaguclu commented 4 years ago

Hello,

When I parse the below user agent, it returns empty. Although it should return 9.

Dalvik/2.1.0 (Linux; U; Android 9; SM-G965U Build/PPR1.180610.011)

nolanwilson commented 4 years ago

Just noting that this happens for any integer version. E.g.:

In [1]: from user_agents import parse

In [2]: parse("Dalvik/2.1.0 (Linux; U; Android 9; SM-G965U Build/PPR1.180610.011)").os.version_string
Out[2]: ''

In [3]: parse("Dalvik/2.1.0 (Linux; U; Android 9.0; SM-G965U Build/PPR1.180610.011)").os.version_string
Out[3]: '9'

I haven't had time to look into the package to see if this is a bug or the intended implementation, but I wanted to tack on why it's happening.

YuanliangZhang commented 4 years ago

I have the same problem there is a go package "github.com/mssola/useragent" can get "9.0" but our project use python who can slove it ~~

karls commented 4 years ago

The issue actually seems to be with https://github.com/ua-parser/uap-python, which this library uses under the hood.

from ua_parser import user_agent_parser
user_agent_parser.Parse("Dalvik/2.1.0 (Linux; U; Android 9; SM-G965U Build/PPR1.180610.011)")['os']
{'family': 'Android', 'major': None, 'minor': None, 'patch': None, 'patch_minor': None}

Edit: Also, ua-parser/uap-parser on PyPI was released in April 2018 (ver 0.8.0), whereas the Github repo shows lots of commits after that. Installing ua-parser/uap-parser from master seems to work for integer versions. But yeah, it's a bit scary to install straight from master, rather than a known good release.