Flask Code -Wie liest man die Datei, die von curl nach Flask gesendet wird?
@app.route('/messages', methods = ['POST'])
def api_message():
if request.headers['Content-Type'] == 'text/plain':
return "Text Message: " + request.data
elif request.headers['Content-Type'] == 'application/json':
f = open(filename,'r')
l = f.readlines()
f.close()
return len(l)
Auf Laufen, erhalte ich Fehler wie -
curl -H "Content-Type:application/json" -X POST http://127.0.0.1:5000/messages --data [email protected]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>
Bin ich die Locke param falsch Zugriff (Dateiname)? Oder ich sende die Datei falsch?
Auch Upload a file to a python flask server using curl
Versuchte
f = request.files['filename']
Dennoch gleichen Fehler machen.
Problem entstand, weil ich [email protected] in curl hatte. curl -H "Inhaltstyp: application/json" -X POST http://127.0.0.1:5000/messages --data @ hello.json und request.get_json scheint das Problem zu lösen. Vielen Dank! –