Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4062922
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:39:36+00:00 2026-05-20T15:39:36+00:00

I have a BaseHandler class that subclasses the Tipfy RequestHandler in my AppEngine site.

  • 0

I have a BaseHandler class that subclasses the Tipfy RequestHandler in my AppEngine site. In it, I have setup a “poor man’s” browser sniffer for mobile devices with a class attribute (a tuple) containing device names.

In a subsequent method, I loop through the device names in the tuple and check them against the user agent string from the Request object. If I get a match, I set an instance attribute called “is_mobile” to True.

In that method, however, Python is giving me a “TypeError: argument of type ‘UserAgent’ is not iterable” error, and I can’t understand why, since the line it is complaining about is not (as far as I understand) a loop.

Here is the code:

class BaseHandler(RequestHandler, AppEngineAuthMixin, AllSessionMixins):

    mobile_devices = ('Android', 'iPhone', 'iPod', 'Blackberry')

    ....

    def detect_mobile_devices(self):
        found_device = False

        for device in self.__class__.mobile_devices:
            if device in self.request.user_agent:
                found_device = True
                break

        self.is_mobile = found_device

Here is the line Python does not like:

File "/path/to/project/app/apps/remember_things/handlers.py", line 56, in detect_mobile_devices
if device in self.request.user_agent:
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:39:37+00:00Added an answer on May 20, 2026 at 3:39 pm

    The expression

    device in self.request.user_agent
    

    will first try to call

    self.request.user_agent.__contains__(device)
    

    If this method does not exist, Python tries to iterate over self.request.user_agent and compares each item it encounters to device. Obviously, the type of self.request.user_agent neither allows .__contains__() nor iteration, hence the error message.

    Also see the documentation of membership test in Python.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so I have a handler below: class PublishHandler(BaseHandler): def post(self): message = self.get_argument(message) some_function(message)
Have following setup: MainActivity class - extends activity MyLayout class - extends View Prefs
Have just started using Google Chrome , and noticed in parts of our site,
I'm battling an error I don't quite understand. I have a class in Java,
Have noticed issue while testing iphone app that if one quickly opens/dismisses a modal
I have a project that adds elements to an AutoCad drawing. I noticed that
I have a script that appends some rows to a table. One of the
I have a new web app that is packaged as a WAR as part
I have a snippet to create a 'Like' button for our news site: <iframe
Have following Java code,that creates StringBuilder with \n,i.e. carriage return delimiters: while (scanner.hasNextLine()){ sb.append(scanner.nextLine()).append(\n);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.