Script runs in debug mode but not regular mode

8 views
Skip to first unread message

Mirko Marovic

unread,
Aug 19, 2025, 10:48:39 AMAug 19
to PyMySQL Users
Hi there,

I've been attempting to connect to my database for the past 4 hours with no success. When I run my script, I get this weird error: pymysql.err.OperationalError: (1045, "Access denied for user 's9qo856odvwdxtlh'@'cst2-160-232.cust.vodafone.cz' (using password: YES)")

From what I understand, instead of using an actual hostname, which I provided in my cnf file, my wi-fi network's name is being appended and I have no idea how to prevent that. HOWEVER, when I run this code in debug mode, it works just fine. 

This is my code: import pymysql, os
if __name__ == "__main__":
    conn = pymysql.connect(read_default_file='nomAdmin/primary_app_db.cnf')
    try :
        with conn.cursor() as cursor:
            cursor.execute("SELECT DATABASE()")
            db_name = cursor.fetchone()
            print(f"Connected to database: {db_name[0]}")
    except pymysql.MySQLError as e:
        print(f"Error connecting to database: {e}")
    finally:
        conn.close()
Reply all
Reply to author
Forward
0 new messages