使用烧瓶和python3获取方法和较大的文本

使用烧瓶和python3获取方法和较大的文本,python,python-3.x,api,flash-message,Python,Python 3.x,Api,Flash Message,我正在尝试运行Flask API,并希望使用API url请求数据。 这是我的代码: from flask import Flask, jsonify, make_response, request app = Flask(__name__) @app.route('/api/v1.0/qanda/', methods=['GET']) def people_api(): text = request.args.get('text') if text is None:

我正在尝试运行Flask API,并希望使用API url请求数据。
这是我的代码:

from flask import Flask, jsonify, make_response, request    
app = Flask(__name__)
@app.route('/api/v1.0/qanda/', methods=['GET'])
def people_api():
    text = request.args.get('text')
    if text is None:
       make_response(jsonify({'error': 'Missing text parameter'}), 400)
    return text
app.run()
我已启动应用程序并尝试点击URL,如下所示:

http://127.0.0.1:5000/api/v1.0/qanda/?text=Inshorts invites applications for its Inshorts Inclusives Campus Program Inshorts is looking for young enthusiastic and innovative minds for its campus program – The Inshorts Inclusives Program. The Inshorts Inclusives is a community of like-minded students working towards Inshorts’ umbrella mission of #Stay Informed. The Inclusives being the torchbearers of the mission, are responsible for designing and executing plans and strategies to keep people informed of and connected to, their surroundings and the world at a larger level. Through this journey, an Inclusive gets exposed to the fields of marketing, content-writing, business development and strategy and gets a hands on experience in these areas. WHAT WOULD BE THE WORK OF AN INSHORTS INCLUSIVE? The main task of an Inclusive would be to come-up with innovative solutions to the given problem - of keeping people informed and creating awareness of the Inshorts app amongst the masses. With this problem statement in mind, an Inclusive would need to be on a constant look out for all possible modes and ways of tackling it. An Inclusive would be responsible for both the ideation and execution of such solutions. Along with this, the Inclusives will also drive the initiative of connecting campuses across the country by creating and managing a common content platform for college students on the Inshorts app. For this they will need to ensure and manage their college’s presence on the app by collating all relevant news and information from their college.
我收到的输出约为我输入的50%:

"Inshorts invites applications for its Inshorts Inclusives Campus Program Inshorts is looking for young enthusiastic and innovative minds for its campus program \u2013 The Inshorts Inclusives Program. The Inshorts Inclusives is a community of like-minded students working towards Inshorts\u2019 umbrella mission of "
我知道
GET
方法有字符限制。我希望避免这个限制,并使用API获取完整的文本。有些人建议使用POST方法,但没有起作用,因为
POST
需要一些表单元素来获取数据

我不知道如何让API接受我想要的字符数。

请告诉我在这种情况下我能做些什么。

为了让POST正常工作,您需要对api做的改动很少:

from flask import Flask, jsonify, make_response, request    
app = Flask(__name__)
@app.route('/api/v1.0/qanda/', methods=['POST'])
def people_api():
    text = request.json.get('text')
    if text is None:
       make_response(jsonify({'error': 'Missing text parameter'}), 400)
    return text
app.run()

text = "Inshorts invites applications for its Inshorts Inclusives Campus Program Inshorts is looking for young enthusiastic and innovative minds for its campus program – The Inshorts Inclusives Program. The Inshorts Inclusives is a community of like-minded students working towards Inshorts’ umbrella mission of #Stay Informed. The Inclusives being the torchbearers of the mission, are responsible for designing and executing plans and strategies to keep people informed of and connected to, their surroundings and the world at a larger level. Through this journey, an Inclusive gets exposed to the fields of marketing, content-writing, business development and strategy and gets a hands on experience in these areas. WHAT WOULD BE THE WORK OF AN INSHORTS INCLUSIVE? The main task of an Inclusive would be to come-up with innovative solutions to the given problem - of keeping people informed and creating awareness of the Inshorts app amongst the masses. With this problem statement in mind, an Inclusive would need to be on a constant look out for all possible modes and ways of tackling it. An Inclusive would be responsible for both the ideation and execution of such solutions. Along with this, the Inclusives will also drive the initiative of connecting campuses across the country by creating and managing a common content platform for college students on the Inshorts app. For this they will need to ensure and manage their college’s presence on the app by collating all relevant news and information from their college."

import requests
r = requests.post("http://127.0.0.1:5000/api/v1.0/qanda/", json={"text": text})
r.text

这听起来像是浏览器强加的限制(255个字符),这里详细回答了这个问题

Flask特别允许您更改
Config
设置,以使用
.MAX\u CONTENT\u length
控制请求长度(如果设置为以字节为单位的值,Flask将通过返回413状态代码来拒绝内容长度大于此的传入请求。)

我认为POST是你的答案,你可能是对的。但我在运行应用程序后出错。查看图片:在该图片中,您仍在发出GET请求,但这是为POST设置的。我试过你的密码。我已经使用了您指定的完整代码作为我的问题的答案。我愿意接受来自浏览器地址栏的输入,并使用API。你的解决方案很好,但不是我想要的。我得到的答案是在命令行上,我想在浏览器上获得输出。请检查一下,对不起,在我的情况下它不起作用。您能告诉我如何增加
GET
方法限制吗?