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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:50:32+00:00 2026-06-04T21:50:32+00:00

Original Question App Engine SDK 1.6.5 Python 2.7 webapp2 I have implemented webapp2 schemes

  • 0

Original Question


App Engine SDK 1.6.5
Python 2.7
webapp2

I have implemented webapp2 schemes to secure pages to https. The issue is that when a user goes to say http:// site/login instead of https:// site/login they get a 404 error due to the schemes not recognising the route.

example main.py

#  Libraries
import webapp2

#  Local Controllers
from controllers.HomeHandler import HomeHandler
from controllers.LoginHandler import LoginHandler

app = webapp2.WSGIApplication([
    webapp2.Route(r'/', HomeHandler),
    webapp2.Route(r'/login', LoginHandler, schemes=['https'], name='login')
], debug=True)

I have added another route / controller below the https route to catch http requests:
webapp2.Route(r'/login', RouteLogin)

RouteLogin.py

#  Libraries
import webapp2

class RouteLogin(webapp2.RequestHandler):
    def get(self):
        self.redirect('https://site.appspot.com/login')

This works, but it seems there should be a better way to do this. Like using htaccess on Apache web server. This is too much like a hack for my liking. I really don’t like hard coded URLs in my code. Not to mention that it is 2 requests which for login isn’t a big deal, but there could be other examples where it ends up costing too much.

NOTE 1: If you are looking at this solution be aware that using the HTTPS schemes also means that you will be unable to use the dev console without deleting the SCHEME or configuring a variable that you set for dev.

NOTE 2: I was able to get a programatic way to serve HTTPS instead of HTTP. I was on the right track with the comment below but it needs an argument.

webapp2.uri_for('login', _scheme='https')
This will give you the correct https://someapp.appspot.com/login url. It unfortunately doesn’t take care of my main problem of how to handle people typing the url into the address bar without https and receiving an error unless I use the hack above. So I am still looking for the WSGI way to route income requests to HTPPS.

Edits: Added Note 1 and clarified the title, I thought it was apparent that I was using WSGI from the source and not CGI.

  • 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-06-04T21:50:33+00:00Added an answer on June 4, 2026 at 9:50 pm

    This is the working code I used in testing for this question.

    Note: The development Web Server (as of this writing v1.6.5) doesn’t support https so your WSGI routes will need the schemes removed to work in the development environment. You can add them back before deployment or create an variable to set the scheme that checks the environment as I did below.

    You can get App Engine Python to reroute the request by defining app.yaml as:
    app.yaml

    application: cgi-vs-wsgi
    version: 1
    runtime: python27
    api_version: 1
    threadsafe: yes
    
    libraries:
    - name: webapp2
      version: latest
    
    handlers:
    
    - url: /profile
      script: main.app
      secure: always
    
    - url: /login
      script: main.app
      secure: always
    
    - url: /.*
      script: main.app
    

    Then in main.py you can declare your WSGI Handlers as normal like:

    main.py

    import webapp2
    import os
    
    # Models
    from models.Shout import Shout
    
    # Controllers
    from controllers.HomeHandler import HomeHandler
    from controllers.LoginHandler import LoginHandler
    from controllers.ProfileHandler import ProfileHandler
    
    if os.environ['SERVER_SOFTWARE'].startswith('Development'):
        app_scheme = 'http'
    else:
        app_scheme = 'https'
    
    app = webapp.WSGIApplication([
        webapp2.Route(r'/login', LoginHandler, name='login', schemes=[app_scheme]),
        webapp2.Route(r'/profile', ProfileHandler, name='profile', schemes=[app_scheme]),
        webapp2.Route(r'/', HomeHandler)
    ], debug=True)
    

    I have uploaded the code for this app to my AE-BaseApp GitHub please feel free to download and use this in your applications. The code is licensed Apache License 2.0.

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

Sidebar

Related Questions

Edit: original question below, but I revise it now that I have some code
Original Question Is there a jQuery method that will check the selection type and
Original Question: i read that for RESTful websites. it is not good to use
Short Question I have a loop that runs 180,000 times. At the end of
I have a PHP-based web app that I'm trying to apply Apache's mod_rewrite to.
Edited the question due to progressive insights :-) I am creating an app that
Per this question: Setting up rake-pipeline for use with handlebars alongside Google App Engine
Update Solved the issue and there was an cycle retain. Original Question Profile showed
First, here's my original question that spawned all of this . I'm using Appcelerator
I was wondering if it was possible to have an alarm style app that

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.