Python-user-agents library not working

I am trying to use python-user-agents . I keep running into many bugs inside the library itself.

At first he referred to from ua_parser import user_agent_parser

which he never defined. So after banging my head, I looked online to see what it might be and found that ua_parser

- this is another library that this project was using. So I downloaded ua_parser

. But now I am getting an error that

TypeError: parse_device() got an unexpected keyword argument 'model'

      

Of course it ua_parser

has a model variable that the python-user-agents library does not expect. Has anyone done a better job with this library? Whoever wrote this did a terrible job. But it seems to be the only one I could find. Any help helping it work well? I want to use it like this to determine if the browser or tablet is mobile or touch device: user_agent.is_mobile

or user_agent.is_touch_capable

oruser_agent.is_tablet

+3


source to share


2 answers


if you look at the readme from the github link it tells you what to install and how to use lib:

You need pyyaml ​​and ua-parser:

pip install pyyaml ua-parser user-agents

      



Working example:

In [1]: from user_agents import parse

In [2]: ua_string = 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B179 Safari/7534.48.3'

In [3]: user_agent = parse(ua_string)

In [4]: user_agent.is_mobile
Out[4]: True

In [5]: user_agent.is_touch_capable 
Out[5]: True

In [6]: user_agent.is_tablet
Out[6]: False

      

+4


source


Actually the new version of ua-parser is incompatible with this, so you need to set ua-parser == 0.3.6



+2


source







All Articles