python - HTTPS with Flask-RESTful and mod_wsgi -
i trying restrict google apps api python client https, using flask-restful , mod_wsgi. api appears work, running errors when point web browsers https url.
i'm new python, flask, , mod_wsgi, have following pared-down example code:
/home/myself/testgoogle/testgoogle.py
#!/usr/local/bin/python import json import os import sys directoryserviceobject import directoryserviceobject flask import flask, request flask.ext.restful import abort, api, resource apiclient import errors 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 )
/home/myself/testgoogle/testgoogle.wsgi
import sys sys.path.insert( 0, "/home/myself/testgoogle" ) testgoogle import app application
/path/to/apache/ssl.conf
<virtualhost 256.256.256.256:5001> servername secured.example.com:5001 wsgiscriptalias / /home/myself/testgoogle/testgoogle.wsgi errorlog /home/myself/error.log loglevel warn customlog /home/myself/access.log combined <directory /home/myself/testgoogle> wsgiprocessgroup testgoogle wsgiapplicationgroup %{global} order deny,allow allow </directory> </virtualhost>
when point web browser https://secured.example.com:5001/orgunitslist
list of google domain's organization units, have error "can't connect server 'secured.example.com'".
if first run "python testgoogle.py" api starts, using web browser ends "code 400, message bad request syntax", , browser hangs. assuming because script expecting http. of course, expected going same url using http works, , list of org units.
what missing? else need, or need differently, in order restrict api calls https?
i appear have fixed issue making following changes:
- testgoogle.py renamed testgoogleclient.py.
- testgoogle.wsgi renamed testgooglewsgi.wsgi , modified last line read
from testgoogleclient import app application
.
for reason, having both .wsgi , .py files same name seemed give me "app not found" errors.
i modified apache config:
- added
listen 256.256.256.256:5001
,wsgisocketprefix /var/run/wsgi
outside of<virtualhost>
section. - added following inside
<virtualhost>
:sslengine on
sslcertificatefile /path/to/my/cert
sslcertificatekeyfile /path/to/my/key
wsgidaemonprocess testgoogleclient python-path=/path/to/python/site-packages
wsgiprocessgroup testgoogleclient
wsgiscriptalias / /home/myself/testgoogle/testgooglewsgi.wsgi
and top off, needed system administrators allow app through firewall.
Comments
Post a Comment