
4주차 mars appy.py 와 index.html 코드 완료 후 실행하니 오류가 뜹니다.
작성한 코드 및 에러 메세지
아래가 제가 작성한 코드이고
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
from pymongo import MongoClient
client = MongoClient('mongodb+srv://sparta:<test>@cluster0.lconjgd.mongodb.net/?retryWrites=true&w=majority')
db = client.dbsparta
@app.route('/')
def home():
return render_template('index.html')
@app.route("/mars", methods=["POST"])
def mars_post():
name_receive = request.form['name_give']
address_receive = request.form['address_give']
size_receive = request.form['size_give']
doc = {'name': name_receive,
'address': address_receive,
'size' : size_receive
}
db.mars.insert_one(doc)
return jsonify({'msg':'저장완료!'})
@app.route("/mars", methods=["GET"])
def mars_get():
return jsonify({'msg':'GET 연결 완료!'})
if __name__ == '__main__':
app.run('0.0.0.0', port=5000, debug=True)
아래가 터미널 오류입니다
(venv)
a@eunji MINGW64 ~/Desktop/Sparta/projects(4주차)/02.mars
$ "c:/Users/a/Desktop/Sparta/projects(4주차)/02.mars/venv/Scripts/python.exe" "c:/Users/a/Desktop/Sparta/projects(4주차)/02.mars/app.py"
* Serving Flask app 'app'
* Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:5000
* Running on http://192.168.0.11:5000
Press CTRL+C to quit
* Restarting with stat
* Debugger is active!
* Debugger PIN: 467-229-222
127.0.0.1 - - [27/Feb/2023 11:33:31] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [27/Feb/2023 11:33:32] "GET /mars HTTP/1.1" 200 -
127.0.0.1 - - [27/Feb/2023 11:57:02] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [27/Feb/2023 11:57:02] "GET /mars HTTP/1.1" 200 -
* Detected change in 'c:\\Users\\a\\Desktop\\Sparta\\projects(4주차)\\02.mars\\app.py', reloading
* Restarting with stat
File "c:\Users\a\Desktop\Sparta\projects(4주차)\02.mars\app.py", line 30
return jsonify({'msg':'저장완료!'})
IndentationError: unexpected indent
(venv)
a@eunji MINGW64 ~/Desktop/Sparta/projects(4주차)/02.mars
$ "c:/Users/a/Desktop/Sparta/projects(4주차)/02.mars/venv/Scripts/python.exe" "c:/Users/a/Desktop/Sparta/projects(4주차)/02.mars/app.py"
* Serving Flask app 'app'
* Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:5000
* Running on http://192.168.0.11:5000
Press CTRL+C to quit
* Restarting with stat
* Debugger is active!
* Debugger PIN: 467-229-222
Exception in thread Thread-1 (serve_forever):
Traceback (most recent call last):
File "C:\Users\a\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 1038, in _bootstrap_inner
self.run()
File "C:\Users\a\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\a\Desktop\Sparta\projects(4주차)\02.mars\venv\Lib\site-packages\werkzeug\serving.py", line 766, in serve_forever
super().serve_forever(poll_interval=poll_interval)
File "C:\Users\a\AppData\Local\Programs\Python\Python311\Lib\socketserver.py", line 233, in serve_forever
ready = selector.select(poll_interval)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\a\AppData\Local\Programs\Python\Python311\Lib\selectors.py", line 323, in select
r, w, _ = self._select(self._readers, self._writers, [], timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\a\AppData\Local\Programs\Python\Python311\Lib\selectors.py", line 314, in _select
r, w, x = select.select(r, w, w, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [WinError 10038] 소켓 이외의 개체에 작업을 시도했습니다
(venv)
a@eunji MINGW64 ~/Desktop/Sparta/projects(4주차)/02.mars
$ "c:/Users/a/Desktop/Sparta/projects(4주차)/02.mars/venv/Scripts/python.exe" "c:/Users/a/Desktop/Sparta/projects(4주차)/02.mars/app.py"
* Serving Flask app 'app'
* Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:5000
* Running on http://192.168.0.11:5000
Press CTRL+C to quit
* Restarting with stat
* Debugger is active!
* Debugger PIN: 467-229-222
