Hi,
I’m having an issue which seems to relate to python and I’ve been trying to find a solution but so far I’ve been failing miserably.
First time here on the forums and I’m sorry if the issue is misplaced, I tried to narrow it down the best I can. I’m not a developer, I can write some simple code to do some testing or do some automations but my coding skills are extremely limited.
On all the systems I’ll describe, these actions were performed on EL9 minimal installs, to which was then added the Development Tools packages (dnf groupinstall 'Development Tools')
I first encountered this issue on a RockyLinux9 system, where python3.11 was installed from source.
I’m deploying a frappe-bench application which uses an external mariadb database server.
After everything was installed the application failed to connect to the database server, returning the error 1045, "Access denied for user 'root'@'10.0.0.1' (using password: YES).
To make sure everything was OK with the credentials and connection, I made a simple shell script to connect to the database server and execute a command select user().
The shell script connects successfully and returns what expected.
+-----------------+
| user() |
+-----------------+
| root@10.0.0.1 |
+-----------------+
Since the frappe framework uses pymysql, I made a similar script in python to connect to the database and do the same command but instead used used mariadb.
This is the python script:
#!/usr/bin/env python3.11
import mariadb
# MariaDB Server details
MARIADB_USER = 'root'
MARIADB_PSWD = 'root-password'
MARIADB_SERV = 'db-server.internal.net'
def execute_query(query):
conn = mariadb.connect(
user=MARIADB_USER,
password=MARIADB_PSWD,
host=MARIADB_SERV,
port=3306
)
cursor = conn.cursor()
cursor.execute(query)
result = cursor.fetchall()
cursor.close()
conn.close()
return result
# List user info
def display_user():
query = "SELECT user()"
result = execute_query(query)
print(result)
display_user()
The python script returns the same error as bench. In full:
$ python3.11 db-test.py
Traceback (most recent call last):
File "/opt/frappe/db-test.py", line 28, in <module>
display_user()
File "/opt/frappe/db-test.py", line 25, in display_user
result = execute_query(query)
^^^^^^^^^^^^^^^^^^^^
File "/opt/frappe/db-test.py", line 9, in execute_query
conn = mariadb.connect(
^^^^^^^^^^^^^^^^
File "/usr/local/lib64/python3.11/site-packages/mariadb/__init__.py", line 146, in connect
connection = connectionclass(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib64/python3.11/site-packages/mariadb/connections.py", line 85, in __init__
super().__init__(*args, **kwargs)
mariadb.OperationalError: Access denied for user 'root'@'10.0.0.1' (using password: YES)
So I did another VM with RL9 and instead of going for python from the sources, I went for the python3.11 on the appstream repo.
The mariadb-connector-c version from repo is 3.2.6 and I was going for mariadb on a lower version, instead of 1.1.10 I was looking to install version 1.0.10or 1.0.11.
Install results in:
$ pip3.11 install mariadb==1.0.11
Defaulting to user installation because normal site-packages is not writeable
Collecting mariadb==1.0.11
Downloading mariadb-1.0.11.zip (85 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 85.9/85.9 kB 1.1 MB/s eta 0:00:00
Preparing metadata (setup.py) ... done
Installing collected packages: mariadb
DEPRECATION: mariadb is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
Running setup.py install for mariadb ... error
error: subprocess-exited-with-error
× Running setup.py install for mariadb did not run successfully.
│ exit code: 1
╰─> [41 lines of output]
10.8.8
running install
/usr/lib/python3.11/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
running build
running build_py
creating build
creating build/lib.linux-x86_64-cpython-311
creating build/lib.linux-x86_64-cpython-311/mariadb
copying mariadb/__init__.py -> build/lib.linux-x86_64-cpython-311/mariadb
creating build/lib.linux-x86_64-cpython-311/mariadb/constants
copying mariadb/constants/__init__.py -> build/lib.linux-x86_64-cpython-311/mariadb/constants
copying mariadb/constants/CLIENT.py -> build/lib.linux-x86_64-cpython-311/mariadb/constants
copying mariadb/constants/INDICATOR.py -> build/lib.linux-x86_64-cpython-311/mariadb/constants
copying mariadb/constants/CURSOR.py -> build/lib.linux-x86_64-cpython-311/mariadb/constants
copying mariadb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-cpython-311/mariadb/constants
running build_ext
building 'mariadb._mariadb' extension
creating build/temp.linux-x86_64-cpython-311
creating build/temp.linux-x86_64-cpython-311/mariadb
gcc -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -march=x86-64-v2 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPY_MARIADB_MAJOR_VERSION=1 -DPY_MARIADB_MINOR_VERSION=0 -DPY_MARIADB_PATCH_VERSION=11 -I/usr/local/include/mariadb -I/usr/local/include/mariadb/mysql -I./include -I/usr/include/python3.11 -c mariadb/mariadb.c -o build/temp.linux-x86_64-cpython-311/mariadb/mariadb.o -DDEFAULT_PLUGINS_SUBDIR=\"/usr/local/lib/mariadb/plugin\"
mariadb/mariadb.c: In function ‘PyInit__mariadb’:
mariadb/mariadb.c:155:35: error: lvalue required as left operand of assignment
155 | Py_TYPE(&MrdbConnection_Type) = &PyType_Type;
| ^
mariadb/mariadb.c:168:31: error: lvalue required as left operand of assignment
168 | Py_TYPE(&MrdbCursor_Type) = &PyType_Type;
| ^
mariadb/mariadb.c:174:29: error: lvalue required as left operand of assignment
174 | Py_TYPE(&MrdbPool_Type) = &PyType_Type;
| ^
mariadb/mariadb.c:180:34: error: lvalue required as left operand of assignment
180 | Py_TYPE(&MrdbIndicator_Type) = &PyType_Type;
| ^
mariadb/mariadb.c:186:38: error: lvalue required as left operand of assignment
186 | Py_TYPE(&Mariadb_Fieldinfo_Type) = &PyType_Type;
| ^
mariadb/mariadb.c:192:38: error: lvalue required as left operand of assignment
192 | Py_TYPE(&Mariadb_DBAPIType_Type) = &PyType_Type;
| ^
error: command '/usr/bin/gcc' failed with exit code 1
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> mariadb
note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
So I went for the sources and got mariadb-connector-c-3.3.10, then installed mariadb==1.1.2 and got the same error.
I repeated the process on an AlmaLinux9 machine.
I removed any special characters from the password and used only uppercase, lowercase and numbers.
the exact same credentials work on the shell script, fail on python.
I made another simpler python script to test, but fails with the same error.
script:
#!/usr/bin/env python3.11
import mariadb
try:
conn = mariadb.connect(
host="server.internal.domain.net",
user="root",
password="password"
)
print("Connected!")
except mariadb.Error as e:
print(f"Error connecting to MariaDB: {e}")
result:
$ python3.11 db-test-2.py
Error connecting to MariaDB: Access denied for user 'root'@'10.0.0.1' (using password: YES)
Does anyone please have an idea? Thanks!