Page MenuHomePhabricator

Unable to connect to Wikireplica databases using Python since the upgrade to Stretch
Closed, ResolvedPublicBUG REPORT

Description

List of steps to reproduce (step by step, including full links if applicable):

  • Log into Toolforge and become your tool account
  • Create a python virtual environment using your tool account: python3 -m venv venv
  • Activate the venv: . ~/venv/bin/activate
  • Install the mysqlclient package for python: pip install mysqlclient
  • Try connecting to a Cloud-Services Wikireplica database:
import MySQLdb

MySQLdb.connect(
    "fawiki.web.db.svc.wikimedia.cloud",
    db="fawiki_p",
    read_default_file="~/replica.my.cnf")

What happens?:
An error message is shown:

MySQLdb._exceptions.OperationalError: (1045, "Access denied for user 'tools.huji'@'10.64.37.28' (using password: NO)")

What should have happened instead?:
You should be able to connect to the database

Other useful information:
I can connect to the Wikireplica DBs from the command line myself, e.g. using sql fawiki_p. This means the config file at ~/replica.my.cnf contains correct information. I can also verify that after connecting to the DB, running SELECT CURRENT_USER returns the same user ID as found in the replica.my.cnf file.

Maybe the issue is that this file is not properly read or used by the Python MYSQLdb package? But it used to work until Stretch upgrade.

Event Timeline

Of note, I was able to get my Python code working by using the toolforge library, but am still curious as to why the MySQLdb library doesn't work anymore.

Of note, I was able to get my Python code working by using the toolforge library, but am still curious as to why the MySQLdb library doesn't work anymore.

Similarly, I can reproduce the issue with mysqlclient, but PyMySQL seems to work fine. (IIRC, that’s what the toolforge library uses, too.)

Have you tried using the absolute path?

Have you tried using the absolute path?

Looks like that’s the issue, with read_default_file="/data/project/TOOLNAME/replica.my.cnf" it works for me.

Huji claimed this task.

Good catch @Chicocvenancio

Closing as Resolved.