Skip to content

TypeError expected string or bytes-like object #4

Description

@ignacionf

Hello. I am using your library to detect mobile devices but every now and then I get the following error:

Traceback (most recent call last):
  File "/opt/app/*************/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 56, in inner
    response = get_response(request)
  File "/opt/app/*************/venv/lib/python3.8/site-packages/sentry_sdk/integrations/django/middleware.py", line 176, in __call__
    return f(*args, **kwargs)
  File "/opt/app/*************/venv/lib/python3.8/site-packages/mobiledetect/middleware.py", line 10, in __call__
    self.process_request(request)
  File "/opt/app/*************/venv/lib/python3.8/site-packages/mobiledetect/middleware.py", line 17, in process_request
    request.device['is_mobile'] = detector.is_mobile()
  File "/opt/app/*************/venv/lib/python3.8/site-packages/mobiledetect/detection.py", line 46, in is_mobile
    return self.match_detection_rules()
  File "/opt/app/*************/venv/lib/python3.8/site-packages/mobiledetect/detection.py", line 105, in match_detection_rules
    if self.match(_regex, user_agent):
  File "/opt/app/*************/venv/lib/python3.8/site-packages/mobiledetect/detection.py", line 128, in match
    matches = re.findall(re.compile(match), user_agents if user_agents else self.user_agent.name)
  File "/usr/lib/python3.8/re.py", line 241, in findall
    return _compile(pattern, flags).findall(string)
TypeError: expected string or bytes-like object

pattern=re.compile('\x08iPhone\x08|\x08iPod\x08')
flags=0
string=None

$ pip freeze | grep mobile
django-mobile-detect==0.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions