Intento enviar una solicitud GET luego de enviar un mensaje a un servidor, pero recibo un error. Creo que es porque
@app.route('/chat',methods=["POST"])
def chat():
try:
user_message = request.form["text"]
response = requests.post('http://localhost:5005/conversations/default/respond', data={"q":user_message})
response = response.json()
print("response :\n",response)
Aquí está el error Avíseme si necesita el rastreo completo.
2018-06-06 13:39:21+0100 [-] "127.0.0.1" - -
[06/Jun/2018:12:39:21 +0000] "POST /conversations/default/respond HTTP/1.1" 500 11082 "-" "python-requests/2.18.4"
2018-06-06 13:42:53+0100 [-] 2018-06-06 13:42:53
ERROR __main__ - Failed to decode json during respond request.
Error: Expecting value: line 1 column 1 (char 0). Request content: 'b'q=Hi''
De verdad funciona bien con el terminal :
mike@mike-thinks:~/Programing/Rasa/myflaskapp$ curl -XPOST localhost:5005/conversations/default/respond -d '{"query":"Hello"}'
[{"recipient_id": "default", "text": "Hello! How can I help?"}]
Actualizacion
@app.route('/chat',methods=["POST"])
def chat():
try:
user_message = request.values.get("text")
response = requests.post('http://localhost:5005/conversations/default/respond', json={"key":user_message})
Da :
'Response' object has no attribute 'get' 127.0.0.1 - - [06/Jun/2018 14:28:30] "POST /chat HTTP/1.1" 200 -
OS Version
Linux 16.04
Flask 1.0.2
Flask-MySQLdb 0.2.0
Flask-WTF 0.14.2
request.values.get('text')
en lugar derequest.form['text']
.response : <Response [400]> 'Response' object has no attribute 'get'