You are not logged in.

#1 2024-11-06 15:35:54

rnv_02
Member
Registered: 2024-10-09
Posts: 5

[SOLVED] python mysql connector not working properly or not at all

>>> import mysql.connector as con
>>> my = con.connect(host="localhost",user="rnv",passwd="rnv",database="arnv")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.12/site-packages/mysql/connector/pooling.py", line 323, in connect
    return MySQLConnection(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/mysql/connector/connection.py", line 179, in __init__
    self.connect(**kwargs)
  File "/usr/lib/python3.12/site-packages/mysql/connector/abstracts.py", line 1438, in connect
    self._post_connection()
  File "/usr/lib/python3.12/site-packages/mysql/connector/abstracts.py", line 1378, in _post_connection
    self.set_charset_collation(charset=self._charset_id)
  File "/usr/lib/python3.12/site-packages/mysql/connector/abstracts.py", line 1353, in set_charset_collation
    self._execute_query(f"SET NAMES '{charset_name}' COLLATE '{collation_name}'")
  File "/usr/lib/python3.12/site-packages/mysql/connector/connection.py", line 1333, in _execute_query
    self.cmd_query(query)
  File "/usr/lib/python3.12/site-packages/mysql/connector/opentelemetry/context_propagation.py", line 97, in wrapper
    return method(cnx, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/mysql/connector/connection.py", line 872, in cmd_query
    result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/mysql/connector/connection.py", line 648, in _handle_result
    raise get_exception(packet)
mysql.connector.errors.DatabaseError: 1273 (HY000): Unknown collation: 'utf8mb4_0900_ai_ci'
>>>

Last edited by rnv_02 (2024-11-10 06:50:36)

Offline

#2 2024-11-06 17:14:17

loqs
Member
Registered: 2014-03-06
Posts: 18,073

Re: [SOLVED] python mysql connector not working properly or not at all

Offline

#3 2024-11-07 16:52:43

rnv_02
Member
Registered: 2024-10-09
Posts: 5

Re: [SOLVED] python mysql connector not working properly or not at all

well i tried looking into them but it seems like theres no dump file to be found with the first one and the second one doesnt have any sort of help to me.

after using reddit solution i get this

Traceback (most recent call last):
  File "/home/aarnav/test.py", line 2, in <module>
    students= pol.connect(
              ^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/mysql/connector/pooling.py", line 323, in connect
    return MySQLConnection(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/mysql/connector/connection.py", line 179, in __init__
    self.connect(**kwargs)
  File "/usr/lib/python3.12/site-packages/mysql/connector/abstracts.py", line 1426, in connect
    self._open_connection()
  File "/usr/lib/python3.12/site-packages/mysql/connector/connection.py", line 373, in _open_connection
    self._do_handshake()
  File "/usr/lib/python3.12/site-packages/mysql/connector/connection.py", line 210, in _do_handshake
    raise get_exception(packet)
mysql.connector.errors.DatabaseError: 1130: Host 'archnav' is not allowed to connect to this MariaDB server

Last edited by rnv_02 (2024-11-07 16:59:32)

Offline

#4 2024-11-07 17:09:29

loqs
Member
Registered: 2014-03-06
Posts: 18,073

Re: [SOLVED] python mysql connector not working properly or not at all

mysql.connector.errors.DatabaseError: 1130: Host 'archnav' is not allowed to connect to this MariaDB server

Is that accurate that the server has not been configured to allow the host archnav to connect? Please use code tags for commands and their outputs e.t.c..
Edit:
Can you from same client connect to that server using `mysql`?

Last edited by loqs (2024-11-07 17:20:05)

Offline

#5 2024-11-08 02:36:30

rnv_02
Member
Registered: 2024-10-09
Posts: 5

Re: [SOLVED] python mysql connector not working properly or not at all

loqs wrote:
mysql.connector.errors.DatabaseError: 1130: Host 'archnav' is not allowed to connect to this MariaDB server

Is that accurate that the server has not been configured to allow the host archnav to connect? Please use code tags for commands and their outputs e.t.c..
Edit:
Can you from same client connect to that server using `mysql`?

Yes I'm able to connect to that server using mysql

Offline

#6 2024-11-08 06:05:53

Perro Muerto
Member
Registered: 2018-08-10
Posts: 6

Re: [SOLVED] python mysql connector not working properly or not at all

Try specifying a different collation in your connection, like `utf8mb4_general_ci`. You can add it in the `connect` function like this:

```python
my = con.connect(
    host="localhost",
    user="rnv",
    passwd="rnv",
    database="arnv",
    charset="utf8mb4",
    collation="utf8mb4_general_ci"
)
```

Offline

#7 2024-11-08 10:36:53

rnv_02
Member
Registered: 2024-10-09
Posts: 5

Re: [SOLVED] python mysql connector not working properly or not at all

Perro Muerto wrote:

Try specifying a different collation in your connection, like `utf8mb4_general_ci`. You can add it in the `connect` function like this:

```python
my = con.connect(
    host="localhost",
    user="rnv",
    passwd="rnv",
    database="arnv",
    charset="utf8mb4",
    collation="utf8mb4_general_ci"
)
```

after making the changes i get

Traceback (most recent call last):
  File "/home/aarnav/test.py", line 2, in <module>
    students= pol.connect(
              ^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/mysql/connector/pooling.py", line 323, in connect
    return MySQLConnection(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/mysql/connector/connection.py", line 179, in __init__
    self.connect(**kwargs)
  File "/usr/lib/python3.12/site-packages/mysql/connector/abstracts.py", line 1426, in connect
    self._open_connection()
  File "/usr/lib/python3.12/site-packages/mysql/connector/connection.py", line 373, in _open_connection
    self._do_handshake()
  File "/usr/lib/python3.12/site-packages/mysql/connector/connection.py", line 210, in _do_handshake
    raise get_exception(packet)
mysql.connector.errors.DatabaseError: 1130: Host 'archnav' is not allowed to connect to this MariaDB server

i am able to connect to my host by using mysql

Offline

#8 2024-11-10 06:49:48

rnv_02
Member
Registered: 2024-10-09
Posts: 5

Re: [SOLVED] python mysql connector not working properly or not at all

I was able to solve this problem that is by making a python virtual env,
Solution steps
mkdir dirforenv
~/dirforenv/bin/pip install mysql.connector
source ~/dirforenv/bin/activate
and then run the python script, it should work now

Offline

#9 2024-11-10 15:48:39

loqs
Member
Registered: 2014-03-06
Posts: 18,073

Re: [SOLVED] python mysql connector not working properly or not at all

You worked around the issue by switching to the deprecated https://pypi.org/project/mysql-connector/? If there is an issue with mysql-connector-python perhaps you should report it upstream?

Offline

Board footer

Powered by FluxBB