実現したいこと
javascript側から送られてきたデータをFlaskで受け取り
そのデータをTkinterを用いてテキストファイルとして保存したいのですが
エラーを吐いてしまい、pythonが強制終了してしまいます。
以下問題のコードです。
Python
1from flask import Flask, render_template, request, jsonify 2import json 3import tkinter as tk 4import tkinter.filedialog as tkfd 5 6app = Flask(__name__) 7 8 9@app.route("/index") 10def index(): 11 return render_template("index5.html") 12 13 14@app.route("/index", methods=["post"]) 15def post(): 16 if request.headers['Content-Type'] != 'application/json': 17 print(request.headers['Content-Type']) 18 return jsonify(res='error'), 400 19 20 json_data = request.json 21 22 root = tk.Tk() 23 root.withdraw() 24 25 file = tkfd.asksaveasfilename( 26 title = "保存場所の選択", 27 filetypes = [("TEXT", ".txt")] 28 ) 29 30 if file: 31 with open(file, 'w') as f: 32 for dict_data in json_data: 33 print(*dict_data.values(), sep=',', file=f) 34 root.destroy() 35 36 root.mainloop() 37 38 return jsonify(res='ok') 39 40 41if __name__ == "__main__": 42 app.run(debug=True) 43
そして、これを実行すると、以下のエラーが表示されます
python3[46018:10100755] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!' *** First throw call stack: ( 0 CoreFoundation 0x00007fff5041facd __exceptionPreprocess + 256 1 libobjc.A.dylib 0x00007fff7aafca17 objc_exception_throw + 48 2 CoreFoundation 0x00007fff50439629 -[NSException raise] + 9 3 AppKit 0x00007fff4d9df5ca -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 317 4 AppKit 0x00007fff4d9dc9f7 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1479 5 AppKit 0x00007fff4da9bd95 -[NSPanel _initContent:styleMask:backing:defer:contentView:] + 50 6 AppKit 0x00007fff4d9dc42a -[NSWindow initWithContentRect:styleMask:backing:defer:] + 45 7 AppKit 0x00007fff4da9bd4a -[NSPanel initWithContentRect:styleMask:backing:defer:] + 64 8 AppKit 0x00007fff4e0b34f5 -[NSSavePanel initWithContentRect:styleMask:backing:defer:] + 592 9 AppKit 0x00007fff4dcaddec +[NSSavePanel _crunchyRawUnbonedPanel] + 550 10 Tk 0x00007fff5c1a3796 Tk_MacOSXTkOwnsCursor + 4095 11 Tcl 0x00007fff5c0446a2 Tcl_ListMathFuncs + 1822 12 Tcl 0x00007fff5c044ef5 Tcl_EvalObjv + 57 13 _tkinter.cpython-36m-darwin.so 0x0000000106fd22c0 Tkapp_Call + 480 14 python3 0x00000001059a4886 PyCFunction_Call + 214 15 python3 0x0000000105a34882 _PyEval_EvalFrameDefault + 26130 16 python3 0x0000000105a381d3 _PyEval_EvalCodeWithName + 2883 17 python3 0x0000000105a3896b fast_function + 411 18 python3 0x0000000105a375b9 call_function + 553 19 python3 0x0000000105a34542 _PyEval_EvalFrameDefault + 25298 20 python3 0x0000000105a381d3 _PyEval_EvalCodeWithName + 2883 21 python3 0x0000000105a3896b fast_function + 411 22 python3 0x0000000105a375b9 call_function + 553 23 python3 0x0000000105a345d5 _PyEval_EvalFrameDefault + 25445 24 python3 0x0000000105a381d3 _PyEval_EvalCodeWithName + 2883 25 python3 0x0000000105a2e227 PyEval_EvalCodeEx + 55 26 python3 0x0000000105981fff function_call + 351 27 python3 0x0000000105956885 PyObject_Call + 101 28 python3 0x0000000105a3473b _PyEval_EvalFrameDefault + 25803 29 python3 0x0000000105a38a09 fast_function + 569 30 python3 0x0000000105a375b9 call_function + 553 31 python3 0x0000000105a34542 _PyEval_EvalFrameDefault + 25298 32 python3 0x0000000105a38a09 fast_function + 569 33 python3 0x0000000105a375b9 call_function + 553 34 python3 0x0000000105a34542 _PyEval_EvalFrameDefault + 25298 35 python3 0x0000000105a38a09 fast_function + 569 36 python3 0x0000000105a375b9 call_function + 553 37 python3 0x0000000105a34542 _PyEval_EvalFrameDefault + 25298 38 python3 0x0000000105a38ee6 _PyFunction_FastCallDict + 998 39 python3 0x0000000105956a46 _PyObject_FastCallDict + 182 40 python3 0x0000000105956bdc _PyObject_Call_Prepend + 156 41 python3 0x0000000105956885 PyObject_Call + 101 42 python3 0x00000001059bced9 slot_tp_call + 153 43 python3 0x0000000105956ad1 _PyObject_FastCallDict + 321 44 python3 0x0000000105a37562 call_function + 466 45 python3 0x0000000105a34542 _PyEval_EvalFrameDefault + 25298 46 python3 0x0000000105a381d3 _PyEval_EvalCodeWithName + 2883 47 python3 0x0000000105a3896b fast_function + 411 48 python3 0x0000000105a375b9 call_function + 553 49 python3 0x0000000105a34542 _PyEval_EvalFrameDefault + 25298 50 python3 0x0000000105a381d3 _PyEval_EvalCodeWithName + 2883 51 python3 0x0000000105a3896b fast_function + 411 52 python3 0x0000000105a375b9 call_function + 553 53 python3 0x0000000105a34542 _PyEval_EvalFrameDefault + 25298 54 python3 0x0000000105a38a09 fast_function + 569 55 python3 0x0000000105a375b9 call_function + 553 56 python3 0x0000000105a34542 _PyEval_EvalFrameDefault + 25298 57 python3 0x0000000105a38a09 fast_function + 569 58 python3 0x0000000105a375b9 call_function + 553 59 python3 0x0000000105a34542 _PyEval_EvalFrameDefault + 25298 60 python3 0x0000000105a38a09 fast_function + 569 61 python3 0x0000000105a375b9 call_function + 553 62 python3 0x0000000105a34542 _PyEval_EvalFrameDefault + 25298 63 python3 0x0000000105a38ee6 _PyFunction_FastCallDict + 998 64 python3 0x0000000105956a46 _PyObject_FastCallDict + 182 65 python3 0x0000000105956bdc _PyObject_Call_Prepend + 156 66 python3 0x0000000105956885 PyObject_Call + 101 67 python3 0x00000001059bddff slot_tp_init + 159 68 python3 0x00000001059b9e04 type_call + 292 69 python3 0x0000000105956ad1 _PyObject_FastCallDict + 321 70 python3 0x0000000105a37562 call_function + 466 71 python3 0x0000000105a34542 _PyEval_EvalFrameDefault + 25298 72 python3 0x0000000105a38a09 fast_function + 569 73 python3 0x0000000105a375b9 call_function + 553 74 python3 0x0000000105a34542 _PyEval_EvalFrameDefault + 25298 75 python3 0x0000000105a38ee6 _PyFunction_FastCallDict + 998 76 python3 0x0000000105956a46 _PyObject_FastCallDict + 182 77 python3 0x0000000105956bdc _PyObject_Call_Prepend + 156 78 python3 0x0000000105956885 PyObject_Call + 101 79 python3 0x0000000105a3473b _PyEval_EvalFrameDefault + 25803 80 python3 0x0000000105a38a09 fast_function + 569 81 python3 0x0000000105a375b9 call_function + 553 82 python3 0x0000000105a34542 _PyEval_EvalFrameDefault + 25298 83 python3 0x0000000105a38a09 fast_function + 569 84 python3 0x0000000105a375b9 call_function + 553 85 python3 0x0000000105a34542 _PyEval_EvalFrameDefault + 25298 86 python3 0x0000000105a38ee6 _PyFunction_FastCallDict + 998 87 python3 0x0000000105956a46 _PyObject_FastCallDict + 182 88 python3 0x0000000105956bdc _PyObject_Call_Prepend + 156 89 python3 0x0000000105956885 PyObject_Call + 101 90 python3 0x0000000105a87376 t_bootstrap + 70 91 libsystem_pthread.dylib 0x00007fff7c4bf2eb _pthread_body + 126 92 libsystem_pthread.dylib 0x00007fff7c4c2249 _pthread_start + 66 93 libsystem_pthread.dylib 0x00007fff7c4be40d thread_start + 13 ) libc++abi.dylib: terminating with uncaught exception of type NSException Abort trap: 6
私はそもそも大きなところで間違っているのでしょうか。
どうかよろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/14 01:49