import flask
from flask import request
from pacfiletesterAPI import PacFileTester
from urlparse import urlparse
from flask import jsonify
app = flask.Flask(__name__)
#app.config["DEBUG"] = False
@app.route('/pac')
def pac():
r = request.args.get('p')
url = request.args.get('u')
domain = request.args.get('d')
Parsed_url = urlparse(url)
Parsed_domain = urlparse(domain)
if r == '':
return "'not enough arguments, please provide a vaild url"
elif url == '':
if domain == '':
return "'not enough arguments, please provide a vaild url"
elif domain == '':
if url == '':
return "'not enough arguments, please provide a vaild domain"
if Parsed_url.netloc == '':
domain = Parsed_url.path.rstrip('/')
else:
domain = Parsed_url.netloc
if not Parsed_url.scheme != 'http' or Parsed_url.scheme != 'https':
url = 'https://' + domain
result = PacFileTester(r, url, domain)
return jsonify(result)
#app.run(host= '0.0.0.0')
if __name__ == "__main__":
app.run(host= '0.0.0.0')
I can run the file fine with python api.py
but when i try to run it with waitress I get the following error
waitress-serve --call 'api:pac'
Traceback (most recent call last):
File "/usr/bin/waitress-serve", line 11, in <module>
sys.exit(run())
File "/usr/lib/python2.7/site-packages/waitress/runner.py", line 280, in run
app = app()
File "/var/www/html/cloud_test3/api.py", line 13, in pac
r = request.args.get('p')
File "/usr/lib/python2.7/site-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
File "/usr/lib/python2.7/site-packages/werkzeug/local.py", line 306, in _get_current_object
return self.__local()
File "/usr/lib64/python2.7/site-packages/flask/globals.py", line 38, in _lookup_req_object
raise RuntimeError(_request_ctx_err_msg)
RuntimeError: Working outside of request context.
This typically means that you attempted to use functionality that needed
an active HTTP request. Consult the documentation on testing for
information about how to avoid this problem.
My question is, why am i getting this error. I don't believe I am working out of the request context. It seems to work just how I want it to on the dev server but not on any other wsgi servers. Waitress is the only one that gave me this error.