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')
我可以用 python api.py 很好地运行文件
但是当我尝试与女服务员一起运行它时,我收到以下错误
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.
我的问题是,为什么我会收到这个错误。我不相信我在请求上下文之外工作。它似乎就像我想要的那样在开发服务器上工作,而不是在任何其他 wsgi 服务器上。女服务员是唯一给我这个错误的人。