
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
4-13에 mongodb에 저장하는 부분인데 저장이 안되네요 refresh를 눌러도 반응이 없네용
작성한 코드 및 에러 메세지
app.py 코드입니다.
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
from pymongo import MongoClient
client = MongoClient('mongodb+srv://sparta:test@cluster0.7qbzrft.mongodb.net/?retryWrites=true&w=majority')
db = client.dbsparta
import requests
from bs4 import BeautifulSoup
from pymongo import MongoClient
import certifi
ca = certifi.where()
client = MongoClient('mongodb+srv://sparta:test@cluster0.symmcqq.mongodb.net/?retryWrites=true&w=majority', tlsCAFile = ca)
db = client.dbsparta
@app.route('/')
def home():
return render_template('index.html')
@app.route("/movie", methods=["POST"])
def movie_post():
url_receive = request.form['url_give']
comment_receive = request.form['comment_give']
headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'}
data = requests.get(url_receive,headers=headers)
soup = BeautifulSoup(data.text, 'html.parser')
ogtitle = soup.select_one('meta[property="og:title"]')['content']
ogimage = soup.select_one('meta[property="og:image"]')['content']
ogdesc = soup.select_one('meta[property="og:description"]')['content']
doc = {
'title':ogtitle,
'desc':ogdesc,
'image':ogimage,
'url':url_receive,
'comment':comment_receive
}
db.EI_4.insert_one(doc)
return jsonify({'msg':'저장완료'})
@app.route("/movie", methods=["GET"])
def movie_get():
return jsonify({'msg':'GET 연결 완료!'})
if __name__ == '__main__':
app.run('0.0.0.0', port=5000, debug=True)
터미널 내용입니다.
admin@DESKTOP-RPFTG8R MINGW64 ~/Downloads/sparta/E.Aproject
$ source c:/Users/admin/Downloads/sparta/E.Aproject/venv/Scripts/activate
(venv)
admin@DESKTOP-RPFTG8R MINGW64 ~/Downloads/sparta/E.Aproject
$ c:/Users/admin/Downloads/sparta/E.Aproject/venv/Scripts/python.exe c:/Users/admin/Downloads/sparta/E.Aproject/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://172.30.1.99:5000
Press CTRL+C to quit
* Restarting with stat
* Debugger is active!
* Debugger PIN: 103-170-862
127.0.0.1 - - [09/May/2023 17:52:50] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [09/May/2023 17:52:50] "GET /movie HTTP/1.1" 200 -
127.0.0.1 - - [09/May/2023 17:53:08] "POST /movie HTTP/1.1" 200 -
