【发布时间】:2016-07-20 01:50:23
【问题描述】:
烧瓶代码 -
@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)
在运行时,我得到错误 -
curl -H "Content-Type:application/json" -X POST http://127.0.0.1:5000/messages --data filename=@hello.json
<!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>
我访问 curl 参数是否错误(文件名)?或者我以错误的方式发送文件?
还有Upload a file to a python flask server using curl
试过了
f = request.files['filename']
仍然,同样的错误。
【问题讨论】: