작성
·
203
0
안녕하세요, 질 좋은강의를 해주셔서 정말 감사하고 많이배우고있습니다. 바쁘실테니 요점만 간단히 하겠습니다.
문제 : 이메일등록하려고 시도할때 DB연결이 안되있어서 @staticmethod인 find부터 걸림
체크해본것 :
mysql 데이터베이스, 테이블, 칼럼 확인 O
파라미터(user_email, blog_id) 잘넘어가는지 확인 O
import pymysql
MYSQL_CONN = pymysql.connect(
host="localhost",
port=3306,
user='root',
passwd='1234',
db='blog_db',
charset='utf8'
)
def conn_mysqldb():
try:
if not MYSQL_CONN.open:
MYSQL_CONN.ping(reconnect=True)
return MYSQL_CONN
except Exception as e:
print(e)
Traceback (most recent call last): File "/Users/joeykang/.conda/envs/Portfolio/lib/python3.8/site-packages/flask/app.py", line 2464, in __call__ return self.wsgi_app(environ, start_response) File "/Users/joeykang/.conda/envs/Portfolio/lib/python3.8/site-packages/flask/app.py", line 2450, in wsgi_app response = self.handle_exception(e) File "/Users/joeykang/.conda/envs/Portfolio/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File "/Users/joeykang/.conda/envs/Portfolio/lib/python3.8/site-packages/flask/app.py", line 1867, in handle_exception reraise(exc_type, exc_value, tb) File "/Users/joeykang/.conda/envs/Portfolio/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise raise value File "/Users/joeykang/.conda/envs/Portfolio/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "/Users/joeykang/.conda/envs/Portfolio/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request rv = self.handle_user_exception(e) File "/Users/joeykang/.conda/envs/Portfolio/lib/python3.8/site-packages/flask_cors/extension.py", line 165, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File "/Users/joeykang/.conda/envs/Portfolio/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception reraise(exc_type, exc_value, tb) File "/Users/joeykang/.conda/envs/Portfolio/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise raise value File "/Users/joeykang/.conda/envs/Portfolio/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request rv = self.dispatch_request() File "/Users/joeykang/.conda/envs/Portfolio/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/Users/joeykang/PycharmProjects/Portfolio/portfolio_view/blog.py", line 23, in set_email user = User.create(user_email, blog_id) File "/Users/joeykang/PycharmProjects/Portfolio/portfolio_control/user_mgmt.py", line 50, in create user = User.find(user_email) File "/Users/joeykang/PycharmProjects/Portfolio/portfolio_control/user_mgmt.py", line 34, in find db_cursor = mysql_db.cursor() AttributeError: 'function' object has no attribute 'cursor'
답변 2
0
0
안녕하세요.
관련 코드만을 봐서는 어떤 문제인지 이해하기 어려워서요. 단순히 연결하기만 하는 코드인데... 아마 다른 코드에서 에러가 난 것 같은데요. 이럴 경우는 코드가 서로 다양하게 연결되어 잇기 때문에, 반드시 새로 제가 드린 코드를 그대로 다운로드 받으셔서, 테스트를 해보신 후, 자신의 코드와 비교해보시는 것이 가장 빠를 것 같습니다. 그렇게 한번 해보시는 것은 어떨까요?