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 6805511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:35:44+00:00 2026-05-26T19:35:44+00:00

I’m migrating a webapp to python 2.7 with GAE and this error message appears:

  • 0

I’m migrating a webapp to python 2.7 with GAE and this error message appears:

File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 129, in _StartResponse     raise InvalidResponseError('headers must be str') InvalidResponseError: headers must be str

What does it mean? I saw someone else had the same problem but I’m not in the same situation. Is there something with my render method from the basehandler class?

My code:

class BaseHandler(webapp.RequestHandler):

    facebook = None
    user = None
    csrf_protect = True


    @property
    def current_user(self):
        if not hasattr(self, "_current_user"):
            self._current_user = None
            cookie = facebook.get_user_from_cookie(
                self.request.cookies, conf.FACEBOOK_APP_ID, conf.FACEBOOK_APP_SECRET)
        logging.debug("logging cookie"+str(cookie))
            if cookie:
                # Store a local instance of the user data so we don't need
                # a round-trip to Facebook on every request
                user = FBUser.get_by_key_name(cookie["uid"])
                logging.debug("user "+str(user))
                logging.debug("username "+str(user.name))

                if not user:
                    graph = facebook.GraphAPI(cookie["access_token"])
                    profile = graph.get_object("me")
                    user = User(key_name=str(profile["id"]),
                                user_id=str(profile["id"]),
                                name=profile["name"],
                                profile_url=profile["link"],
                                access_token=cookie["access_token"])
                    user.put()
                elif user.access_token != cookie["access_token"]:
                    user.access_token = cookie["access_token"]
                    user.put()
                self._current_user = user
        return self._current_user

    def initialize(self, request, response):


        super(BaseHandler, self).initialize(request, response)

        try:
            self.init_facebook()
            self.init_csrf()
            self.response.headers[u'P3P'] = u'CP=HONK'  # iframe cookies in IE
        except Exception, ex:
            self.log_exception(ex)
            raise

    def handle_exception(self, ex, debug_mode):


        self.log_exception(ex)
        self.render(u'error', trace=traceback.format_exc(),
                    debug_mode=debug_mode)

    def log_exception(self, ex):


        msg = (str(ex) or ex.__class__.__name__) + u': \n' \
            + traceback.format_exc()
        if isinstance(ex, urlfetch.DownloadError) or isinstance(ex,
                DeadlineExceededError) or isinstance(ex, CsrfException) \
            or isinstance(ex, taskqueue.TransientError):
            logging.warn(msg)
        else:
            logging.error(msg)

    def set_cookie(
        self,
        name,
        value,
        expires=None,
        ):


        if value is None:
            value = 'deleted'
            expires = datetime.timedelta(minutes=-50000)
        jar = Cookie.SimpleCookie()
        jar[name] = value
        jar[name]['path'] = u'/'
        if expires:
            if isinstance(expires, datetime.timedelta):
                expires = datetime.datetime.now() + expires
            if isinstance(expires, datetime.datetime):
                expires = expires.strftime('%a, %d %b %Y %H:%M:%S')
            jar[name]['expires'] = expires
        self.response.headers.add_header(*jar.output().split(u': ', 1))

    def render(self, name, **data):


        if not data:
            data = {}
        data[u'js_conf'] = json.dumps({u'appId': conf.FACEBOOK_APP_ID,
                u'canvasName': conf.FACEBOOK_CANVAS_NAME,
                u'userIdOnServer'
                : (self.user.user_id if self.user else None)})
        data[u'logged_in_user'] = self.user
        data[u'message'] = self.get_message()
        data[u'csrf_token'] = self.csrf_token
        data[u'canvas_name'] = conf.FACEBOOK_CANVAS_NAME
        self.response.out.write(template.render(os.path.join(os.path.dirname(__file__),
                                'templates', name + '.html'), str(data)))

    def init_facebook(self):


        facebook = Facebook()
        user = None

        # initial facebook request comes in as a POST with a signed_request

        if u'signed_request' in self.request.POST:
            facebook.load_signed_request(self.request.get('signed_request'
                    ))

            # we reset the method to GET because a request from facebook with a
            # signed_request uses POST for security reasons, despite it
            # actually being a GET. in webapp causes loss of request.POST data.

            self.request.method = u'GET'
            self.set_cookie('u', facebook.user_cookie,
                            datetime.timedelta(minutes=1440))
        elif 'u' in self.request.cookies:
            facebook.load_signed_request(self.request.cookies.get('u'))

        # try to load or create a user object

        if facebook.user_id:
            user = User.get_by_key_name(facebook.user_id)
            if user:

                # update stored access_token

                if facebook.access_token and facebook.access_token \
                    != user.access_token:
                    user.access_token = facebook.access_token
                    user.put()

                # refresh data if we failed in doing so after a realtime ping

                if user.dirty:
                    user.refresh_data()

                # restore stored access_token if necessary

                if not facebook.access_token:
                    facebook.access_token = user.access_token

            if not user and facebook.access_token:
                me = facebook.api(u'/me', {u'fields': _USER_FIELDS})
                try:
                    friends = [user[u'id'] for user in me[u'friends'
                               ][u'data']]
                    user = User(
                        key_name=facebook.user_id,
                        user_id=facebook.user_id,
                        friends=friends,
                        access_token=facebook.access_token,
                        name=me[u'name'],
                        email=me.get(u'email'),
                        picture=me[u'picture'],
                        )
                    user.put()
                except KeyError, ex:
                    pass  # ignore if can't get the minimum fields

        self.facebook = facebook
        self.user = user

    def init_csrf(self):


        self.csrf_token = self.request.cookies.get(u'c')
        if not self.csrf_token:
            self.csrf_token = str(uuid4())[:8]
            self.set_cookie('c', self.csrf_token)
        if self.request.method == u'POST' and self.csrf_protect \
            and self.csrf_token != self.request.POST.get(u'_csrf_token'
                ):
            raise CsrfException(u'Missing or invalid CSRF token.')

    def set_message(self, **obj):


        self.set_cookie('m',
                        (base64.b64encode(json.dumps(obj)) if obj else None))

    def get_message(self):


        message = self.request.cookies.get(u'm')
        if message:
            self.set_message()  # clear the current cookie
            return json.loads(base64.b64decode(message))

import random
from google.appengine.api import files, images
class CyberFazeHandler(BaseHandler):

    """Handle the home page that renders 3 random images"""
    def get_random_image(self, category):
        """get a random image O(1) by category"""
        q = FileInfo.all()
        q.filter('category =', category)
        q.filter('randomvalue >=', random.random())
        return q.get()

    def get(self):
        logging.info('get ')
        """build up the random face from the random body """
    try:             
          eyes_image = self.get_random_image(category='eyes')
          nose_image = self.get_random_image(category='nose')
          mouth_image = self.get_random_image(category='mouth')
          logging.info('set mouth id '+str(eyes_image.blob.key()))
          eyes_data = blobstore.fetch_data(eyes_image.blob.key(), 0, 50000)
          eyes_img = images.Image(image_data=eyes_dat
          nose_data = blobstore.fetch_data(nose_image.blob.key(), 0, 50000)
          nose_img = images.Image(image_data=nose_data)
          logging.info('eyes image ')
          mouth_data = blobstore.fetch_data(mouth_image.blob.key(),0, 50000)
          mouth_img = images.Image(image_data=mouth_data)
          minimum = int(min(eyes_img.width, nose_img.width, mouth_img.width))
          eyes_url = images.get_serving_url(str(eyes_image.blob.key()), size=minimum)
          nose_url = images.get_serving_url(str(nose_image.blob.key()), size=minimum)
          mouth_url = images.get_serving_url(str(mouth_image.blob.key()), size=minimum)


          self.render('cyberfaze', minimum=minimum, eyes_image=eyes_image, eyes_url=eyes_url, nose_image=nose_image, nose_url=nose_url, mouth_image=mouth_image, mouth_url=mouth_url, form_url=blobstore.create_upload_url('/upload'),)
  • 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-26T19:35:44+00:00Added an answer on May 26, 2026 at 7:35 pm

    self.response.headers[u'P3P'] = u'CP=HONK'

    Try passing strings here instead of casting to unicode.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:

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.