首页 > 解决方案 > 无法使用python从mysql数据库中检索数据

问题描述

我无法从我的数据库中检索数据。我似乎已经尝试了互联网上的每个页面来尝试让它工作。我确信答案非常简单,但作为非编码人员,我只是不知道它是什么。您能给我的任何帮助将不胜感激。

from twilio.twiml.messaging_response import MessagingResponse
from flask_sqlalchemy import SQLAlchemy
import mysql.connector

def main():
    cnx = mysql.connector.connect(user='*****', password='****', host='*****.mysql.pythonanywhere-services.com', database='*****$Working')
    cursor = cnx.cursor()
    resp = MessagingResponse()

    query = "select * from messages"
    cursor.execute(query)
    for i in cursor.fetchall():
        resp.message(i)

    cursor.close()
    cnx.close()
    return str(resp)

标签: pythonmysqlpythonanywhere

解决方案


推荐阅读