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

  • Home
  • SEARCH
  • 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 3345308
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:10:14+00:00 2026-05-18T01:10:14+00:00

I have a class that doesn’t extend webapp.RequestHandler , and I can’t use self.response.out.write()

  • 0

I have a class that doesn’t extend webapp.RequestHandler, and I can’t use self.response.out.write(), I get:

AttributeError: Fetcher instance has no attribute ‘response’

If I extend webapp.RequestHandler (I thought it would work), I get:

AttributeError: ‘Fetcher’ object has no attribute ‘response’

How can I use that method properly? Sometimes print doesn’t work either; I just get a blank screen.

EDIT:

app.yaml:

application: fbapp-lotsofquotes
version: 1
runtime: python
api_version: 1

handlers:
- url: .*
  script: main.py

source (the problematic line is marked with #<- HERE):

import random
import os

from google.appengine.api import users, memcache
from google.appengine.ext import webapp, db
from google.appengine.ext.webapp import util, template
from google.appengine.ext.webapp.util import run_wsgi_app

import facebook


class Quote(db.Model):
    author = db.StringProperty()
    string = db.StringProperty()
    categories = db.StringListProperty()
    #rating = db.RatingProperty()


class Fetcher(webapp.RequestHandler):
    '''
    Memcache keys: all_quotes
    '''

    def is_cached(self, key):
        self.fetched = memcache.get(key)
        if self.fetched:
            print 'ok'#return True
        else:
            print 'not ok'#return False


    #TODO: Use filters!
    def fetch_quotes(self):
        quotes = memcache.get('all_quotes')
        if not quotes:
            #Fetch and cache it, since it's not in the memcache.
            quotes = Quote.all()
            memcache.set('all_quotes',quotes,3600)
        return quotes

    def fetch_quote_by_id(self, id):
        self.response.out.write(id) #<---------- HERE


class MainHandler(webapp.RequestHandler):

    def get(self):
        quotes = Fetcher().fetch_quotes()
        template_data = {'quotes':quotes}
        template_path = 'many.html'
        self.response.out.write(template.render(template_path, template_data))


class ViewQuoteHandler(webapp.RequestHandler):

    def get(self, obj):
        self.response.out.write('viewing quote<br/>\n')
        if obj == 'all':
            quotes = Fetcher().fetch_quotes()
            self.render('view_many.html',quotes=quotes)
        else:
            quotes = Fetcher().fetch_quote_by_id(obj)
            '''for quote in quotes:
                print quote.author
                print quote.'''


    def render(self, type, **kwargs):
        if type == 'single':
            template_values = {'quote':kwargs['quote']}
            template_path = 'single_quote.html'
        elif type == 'many':
            print 'many'

        self.response.out.write(template.render(template_path, template_values))


'''
CREATORS
'''
class NewQuoteHandler(webapp.RequestHandler):

    def get(self, action):
        if action == 'compose':
            self.composer()
        elif action == 'do':
            print 'hi'

    def composer(self):
        template_path = 'quote_composer.html'
        template_values = ''
        self.response.out.write(template.render(template_path,template_values))

    def post(self, action):
        author = self.request.get('quote_author')
        string = self.request.get('quote_string')
        print author, string

        if not author or not string:
            print 'REDIRECT'

        quote = Quote()
        quote.author = author
        quote.string = string
        quote.categories = []
        quote.put()


def main():
    application = webapp.WSGIApplication([('/', MainHandler),
                                          (r'/view/quote/(.*)',ViewQuoteHandler),
                                          (r'/new/quote/(.*)',NewQuoteHandler) ],
                                         debug=True)
    util.run_wsgi_app(application)


if __name__ == '__main__':
    main()
  • 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-18T01:10:15+00:00Added an answer on May 18, 2026 at 1:10 am

    You’re not routing to Fetcher when you initialize a WSGIApplication. Rather, you create an instance manually in other handlers. Thus, App Engine will not initialize your request and response properties. You can manually do so in from the handlers you route to, such as MainHandler and ViewQuoteHandler. E.g.:

    fetcher = Fetcher()
    fetcher.initialize(self.request, self.response)
    quotes = fetcher.fetch_quotes()
    

    Note that fetcher really doesn’t have to be a RequestHandler. It could be a separate class or function. Once you have request and response objects, you can pass them around as you choose.

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

Sidebar

Related Questions

I have class method that returns a list of employees that I can iterate
I have a class that I want to use to store properties for another
I have a class that after it does some stuff, sends a JMS message.
Using C# .NET 2.0, I have a composite data class that does have the
I have a class that map objects to objects, but unlike dictionary it maps
I have a class that I wish to expose as a remote service using
I have a class that looks like this public class SomeClass { public SomeChildClass[]
I have a class that creates several IDisposable objects, all of these objects are
I have a class that encapsulates tcp socket communications with a server. For each
I have a class that processes a 2 xml files and produces a text

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.