cURLを使用してファイルをFlaskビューに投稿したいとします。しかし、私は400エラーに応答します。なぜ以下のコマンドが失敗するのですか?cURLを使用してFlaskにファイルを投稿すると、400エラーが返されます
@app.route('/deploy/partial', methods=['POST'])
def postfile():
try:
file = request.files['file']
filename = secure_filename(file.filename)
file.save(os.path.join('/home/test/test.txt', filename))
return 'OK', 200
except:
print("Unexpected error:", sys.exc_info()[0])
raise
curl -X POST -H "Content-Type: multipart/form-data" -F "[email protected]" http://127.0.0.1:25252/deploy/partial
Unexpected error: <class 'werkzeug.exceptions.HTTPException.wrap.<locals>.newcls'>
127.0.0.1 - - [12/Oct/2016 22:57:43] "POST /deploy/partial HTTP/1.1" 400
HTTP/1.1 100 Continue
HTTP/1.0 400 BAD REQUEST
Content-Type: text/html
Content-Length: 192
Server: Werkzeug/0.11.11 Python/3.4.3
Date: Wed, 12 Oct 2016 19:31:07 GMT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not understand.</p>
こんにちは、これはapiに関する部分ですが、require _auth関数はうまく動作し、大きなコードブロックを避けるためにいくつかのtryを削除しました。 IDE(pyCharm)コンソールでエラーが表示されます。 –
戻り値がtry/except文にある場合、表示されるメッセージはスローされた例外です。 –
私は何も想定していない、400エラーがFlaskによって返され、それはcUrlに送信された応答ヘッダーにある。それはコンソールにも表示されています。私は完全なコードで投稿を編集しています。 –