I am trying to loop through a number of mysql hosts which have the same connection info and execute the same query on each of them & fetch the results.
I'm still learning python & am stuck on the following;
import pymysql
ENDPOINTS=['endpoint01', 'endpoint02', 'endpoint03', 'endpoint04']
USER="SOME_USER"
PASS="SOME_PASSWORD"
print("Testing")
for x in ENDPOINTS:
# Open database connection
DATAB = pymysql.connect(x,USER,PASS)
cursor = DATAB.cursor()
cursor.execute("show databases like 'THIS%'")
data = cursor.fetchall()
print (data)
DATAB.close()
And this is the error I receive;
DATAB = pymysql.connect(x,USER,PASS)
TypeError: __init__() takes 1 positional argument but 4 were given
-
I think you need to replace ENDPOINTS with x in the line that's failing.Ben– Ben2022年05月10日 19:50:43 +00:00Commented May 10, 2022 at 19:50
-
@Ben I tried that (replacing ENDPOINTS wth x in the failing line) & receive the same error.paulg– paulg2022年05月10日 19:56:05 +00:00Commented May 10, 2022 at 19:56
1 Answer 1
You're passing the parameters incorrectly. Try
DATAB = pymysql.connect(host=x,user=USER,password=PASS):
Sign up to request clarification or add additional context in comments.
Comments
default