0

Good Afternoon, I wrote a query in MySQL, and I want to execute the same query in Python. The Code I wrote as Follows. 1.

import mysql.connector
from mysql.connector import Error


try:
connection = mysql.connector.connect(host='localhost',
                                      database='AdventureWorks2012',
                                      user='root',
                                      password='r@#*****')
sql_select_Query = "select * from Person.person"
    cursor = connection.cursor()
    cursor.execute(sql_select_Query)
    records = cursor.fetchall()

However, I'm getting following error message while running part two- ''File "", line 5 password='r@#*****') ^ SyntaxError: unexpected EOF while parsing''

Any suggestion please how to overcome this problem?

2

1 Answer 1

1

You are missing the except clause:

try:
    connection = mysql.connector.connect(host='localhost',
                                      database='AdventureWorks2012',
                                      user='root',
                                      password='r@#*****')
except Exception as e:
    print(e)

You should check the documentation for more information.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.