0

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
2
  • I think you need to replace ENDPOINTS with x in the line that's failing. Commented May 10, 2022 at 19:50
  • @Ben I tried that (replacing ENDPOINTS wth x in the failing line) & receive the same error. Commented May 10, 2022 at 19:56

1 Answer 1

4

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

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.