这是我的代码
from flask import Flask, request
from flask_restful import Resource, Api
app = Flask(__name__)
app.config['DEBUG'] = True
api = Api(app)
# Make the WSGI interface available at the top level so wfastcgi can get it.
wsgi_app = app.wsgi_app
class Default(Resource):
def get(self, name):
"""Renders a sample page."""
return "Hello " + name
class LiveStats(Resource):
def get(self, url):
return "Trying to get " + url
# data = request.get(url)
# return data
api.add_resource(Default, '/default/<string:name>') # Route_1
api.add_resource(LiveStats, '/liveStats/<path:url>') # Route_2
if __name__ == '__main__':
import os
HOST = os.environ.get('SERVER_HOST', 'localhost')
try:
PORT = int(os.environ.get('SERVER_PORT', '5555'))
except ValueError:
PORT = 5555
app.run(HOST, PORT)
首先,这篇文章帮助很大how-to-pass-urls-as-parameters-in-a-get-request-within-python-flask-restplus
改变我原来拥有的
api.add_resource(LiveStats, '/liveStats/<string:url>') # Route_2
对此
api.add_resource(LiveStats, '/liveStats/<path:url>') # Route_2
摆脱了404错误,我有,但现在我注意到,它没有通过所有的网址
如果我尝试这个例子
localhost:60933/liveStats/http://address/Statistics?NoLogo=1%26KSLive=1
我明白了
Trying to get http://address/Statistics
所以它已经起飞了?NoLogo=1%26KSLive=1
你如何预防这种情况
?
后面的所有字符都被视为参数From the docs:也许您可以对查询字符串进行编码,以便在后端将其作为单个参数检索,但不确定它是否有用
如果不想单独访问args,you can access the full query string:
综上所述,我认为这会对你有用:
相关问题 更多 >
编程相关推荐