I request help to solve this.

61 views
Skip to first unread message

Osmer Romero

unread,
Jan 15, 2022, 12:45:04 PM1/15/22
to PyMySQL Users

Good afternoon, I am new to programming and I have a small application on a server, but I have to refresh the server so that it can give me access to the databases. I am working with pymysql, could you help me, I leave you the email that the hosting sent me

You are creating your database connection at import time, so it times out. Only make your connection to your database when you need it in each request. So instead of

db_connection = connect_to_database()

def view():;

    do_something(db_connection)


do

def view():

    db_connection = connect_to_database()

    do_something(db_connection)

    db_connection.close()


That way, every request has a fresh database connection that is closed when you are finished using it.


Thanks
Glenn

PythonAnywhere: Develop and host Python from your browser <https://www.pythonanywhere.com/>

Reply all
Reply to author
Forward
0 new messages