
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
안녕하세요. 매 프로잭트를 새로 열고 세팅할 때 마다 환경설정에 괴로운 경험을 하고 있습니다. 그 동안에는 축적된 노하우를 바탕으로 DB연결이 안 되거나, 호스팅이 안 되는 문제를 돌파해 갔습니다만, 정상 작동했던 화성땅 프로젝트에서 코드를 이식하고, 라이브러리 설치도 잘 했는데도 같은 문제가 일어나고 있습니다.
DB 컬렉션에 movies 폴더가 생기지 않고 있고, 데이터의 POST 도 안 되고 있습니다.
작성한 코드 및 에러 메세지
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
from pymongo import MongoClient
import certifi
import requests
from bs4 import BeautifulSoup
ca = certifi.where()
url = 'mongodb+srv://sparta:test@cluster0.fuzltx4.mongodb.net/?retryWrites=true&w=majority'
client = MongoClient(url, 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,
'imange':ogimage,
'comment':comment_receive
}
db.movies.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=5001, debug=True)
