Unable to load the mariadb module

So, I want to utilize mariaDB. Should be easy… I thought.
So, I added the mariadb python package, Which gave me an error.

So i added mariadb-dev system package, which at least gave me a relatable error. (See last in this post).

If i use mysql-connector I get errors about utf8 not supported, So I thought I’d give the proper packages a go.

Google has not given me any usable insight in what simple thing I am missing here.

Collecting mariadb
  Downloading mariadb-1.1.4.zip (97 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 97.4/97.4 kB 7.6 MB/s eta 0:00:00
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'error'
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [8 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-gib6dogy/mariadb_5f5eb1d16844452c98e1c78b8426dd67/setup.py", line 27, in <module>
          cfg = get_config(options)
        File "/tmp/pip-install-gib6dogy/mariadb_5f5eb1d16844452c98e1c78b8426dd67/mariadb_posix.py", line 64, in get_config
          print('MariaDB Connector/Python requires MariaDB Connector/C '
      TypeError: not enough arguments for format string
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
[15:12:28] FATAL: Failed installing package mariadb
cont-init: info: /etc/cont-init.d/appdaemon.sh exited 1
cont-init: warning: some scripts exited nonzero
s6-rc: warning: unable to start service legacy-cont-init: command exited 1
/run/s6/basedir/scripts/rc.init: warning: s6-rc failed to properly bring all the services up! Check your logs (in /run/uncaught-logs/current if you have in-container logging) for more information.
prog: fatal: stopping the container.
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

Hi there!

I ran into this exact issue just now, and I found this post while googling for solutions.
I too was unable to find any solution online, but I was able to figure out the problem myself.

I took a look at the actual source code responsible for producing the error, and I discovered that the issue was actually a bad version of the MariaDB Connector/C, as can be seen here: https://github.com/mariadb-corporation/mariadb-connector-python/blob/4c75199a7548d2636bb8cae0966c91458818193c/mariadb_posix.py#L64

I did some digging, and I was able to discern that my distro installed a version of the connector that was too old by default, I was able to fix the issue by performing the following steps:

First, uninstall libmariadb3 and libmariadb-dev if already installed using the distro defaults

sudo apt remove libmariadb3 libmariadb-dev && sudo apt autoremove

Download a setup utility from the official MariaDB site

wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup

[Optional] Check that the downloaded file matches the checksum

echo "733cf126b03f73050e242102592658913d10829a5bf056ab77e7f864b3f8de1f  mariadb_repo_setup" \
    | sha256sum -c -

Run the utility

sudo ./mariadb_repo_setup \
   --mariadb-server-version="mariadb-10.6"

Install the mariadb libraries again

sudo apt install libmariadb3 libmariadb-dev

Most of the steps are outlined here as well, if you want the actual source: Install MariaDB Connector/C — MariaDB Enterprise Documentation

And finally, attempt to install mariadb again using pip.
Hope this fixes your issue!

Thank you. Unfortunately I’m trying to run this in the Appdaemon addon for HomeAssistant. So, the entire Python SUbsystem is a bit of a black box unfortunately.

But, Ok, this at least gives me something to go on. Thank you!

Hey, Did you work out a solution to this in the end? Would be interested if you did!