title: HTTPS with Flask-RESTful and mod_wsgi
body: <p>I am trying to restrict a Google Apps API Python client to HTTPS, using Flask-RESTful and mod_wsgi.  The API itself appears to work, but I am running into errors when I point web browsers to the HTTPS url.</p>
  
  <p>I'm fairly new to Python, Flask, and mod_wsgi, but I have the following pared-down example code:</p>
  
  <p><strong>/home/myself/testgoogle/testgoogle.py</strong></p>
  
  <pre><code>#!/usr/local/bin/python
  import json
  import os
  import sys
  
  from DirectoryServiceObject import DirectoryServiceObject
  from flask import Flask, request
  from flask.ext.restful import abort, Api, Resource
  from apiclient import errors
  from apiclient.discovery import build
  
  directory_service_object = DirectoryServiceObject().service_object
  
  app = Flask( __name__ )
  app.debug = True
  api = Api( app )
  
  class OrgUnitsList( Resource ):
      def get( self ):
          all_org_units = {}
  
          params = { "customerId": "my_customer" }
  
          try:
              all_org_units = directory_service_object.orgunits().list( **params ).execute()
          except errors.HttpError, e:
              error = json.loads(e.content)
              return error
  
          return all_org_units
  
  api.add_resource( OrgUnitsList, "/orgunitslist" )
  
  if __name__ == "__main__":
      app.run( host="secured.example.com", port=5001 )
  </code></pre>
  
  <p><strong>/home/myself/testgoogle/testgoogle.wsgi</strong></p>
  
  <pre><code>import sys
  sys.path.insert( 0, "/home/myself/testgoogle" )
  from testgoogle import app as application
  </code></pre>
  
  <p><strong>/path/to/apache/ssl.conf</strong></p>
  
  <pre><code>&lt;VirtualHost 256.256.256.256:5001&gt;
  ServerName secured.example.com:5001
  
  WSGIScriptAlias / /home/myself/testgoogle/testgoogle.wsgi
  
  ErrorLog /home/myself/error.log
  LogLevel warn
  CustomLog /home/myself/access.log combined
  
  &lt;Directory /home/myself/testgoogle&gt;
    WSGIProcessGroup testgoogle
    WSGIApplicationGroup %{GLOBAL}
    Order deny,allow
    Allow from all
  &lt;/Directory&gt;
  
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>When I point my web browser to <code>https://secured.example.com:5001/orgunitslist</code> to get a list of my Google domain's organization units, I have the error "can't connect to the server 'secured.example.com'".</p>
  
  <p>If I first run "python testgoogle.py" the API starts, but using the web browser ends up with "code 400, message Bad request syntax", and the browser hangs.  I am assuming it is because the script is expecting HTTP.  Of course, as expected going to the same URL using HTTP works, and I get a list of the org units.</p>
  
  <p>What am I missing?  What else do I need, or need to do differently, in order to restrict API calls to HTTPS?</p>