Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError occurs when I run device_detector.py #35

Closed
michaelfrank1 opened this issue Nov 12, 2020 · 3 comments
Closed

ImportError occurs when I run device_detector.py #35

michaelfrank1 opened this issue Nov 12, 2020 · 3 comments

Comments

@michaelfrank1
Copy link

This is the resulting error.

Traceback (most recent call last):
File "device_detector.py", line 1, in
from .lazy_regex import RegexLazyIgnore
ImportError: attempted relative import with no known parent package

@thinkwelltwd
Copy link
Owner

device_detector.py is not supposed to be "run". Are you following the Usage Notes?

Please include the python version you're using, and the exact code you're executing.

@michaelfrank1
Copy link
Author

I probably don't have a grasp on what I'm supposed to be running. I am a NOOB to Python, even though I am starting to develop Python test tools for a living.

All I am doing is running the following at the command prompt:
python device_detector.py

Which you indicated is not the way to run it.

I looked at the Usage Notes, but all I see is the results of running the tool.

Could you please provide me with some guidance. I don't want to keep bugging you about this.

It's probably very easy to run in your eyes, but I am a bit confused.

Please let me know how I am supposed to run this script so that I get results.

Thank you.

BTW: My python version is 3.8.5.

@thinkwelltwd
Copy link
Owner

All I am doing is running the following at the command prompt:
python device_detector.py
Could you please provide me with some guidance.

device_detector is a library to use in your own scripts, not a self-standing script. The Usage Notes are all the guidance that I can provide. Python fluency has to come from other sources.

Open your python interpreter and paste the following lines (from the Usage Notes)

from device_detector import DeviceDetector

ua = 'Mozilla/5.0 (Linux; Android 4.3; C5502 Build/10.4.1.B.0.101) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.136 Mobile Safari/537.36'
device = DeviceDetector(ua).parse()
device.all_details

If you want to parse a file of UA strings, you'll have to write your own python script to do it. Something like so:

ua_parser.py

#!/usr/bin/env python3
from device_detector import DeviceDetector

with open('/path/to/ua/strings.txt', 'r'): as ua_file:
    for ua in ua_file:
        dd = DeviceDetector(ua.strip()).parse()
        print(dd.all_details)

And with that, I'll close the ticket as this is not a bug. Thanks for checking out device_detector and all the best in learning python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants