Randomly Can't connect to MariaDB from Python & Django

I’m running windows server 2016 vm with Diango 3.1.1, Python 3.7.9 (mysqlclient 2.0.1) and MariaDB 10.5.4.
After a few hours/minutes randomly django web pages do not connect for a few seconds with the error:

Other python scripts connecting the database fail with the same error.

File "c:\Python37\lib\site-packages\MySQLdb\__init__.py", line 130, in Connect
  return Connection(*args, **kwargs)
File "c:\Python37\lib\site-packages\MySQLdb\connections.py", line 185, in __init__
  super().__init__(*args, **kwargs2)
MySQLdb._exceptions.OperationalError: (2002, "Can't connect to MySQL server on '127.0.0.1' (10060)")

I have no errors in MariaDB logs or in event viewer.

With “SELECT * FROM information_schema.processlist” I have less than 15 processes

My.ini

[mysqld]
datadir=C:/Program Files/MariaDB 10.5/data
port=3306
innodb_buffer_pool_size=1023M
slow_query_log=1
long_query_time=5.0
bind-address    = 0.0.0.0
max_allowed_packet=64M

Can anybody help me solve this? Any reply will be appreciated.

You might need to do some more detailed investigation of your server.

If the server runs fine for a period of time, then throws an error, then works again, there’s a good chance that it’s something environmental in the server rather than anything specifically wrong with either Django or MariaDB.

If I were trying to debug this, I’d be monitoring the server closely - and since you mentioned that this is a VM, I’d also be watching the host too. Then I would run one or more clients that just kept trying to retrieve pages, possibly even doing a network trace to follow the traffic.

But I don’t think there’s enough information here to even begin to offer a diagnosis. This might be one of those problems where you just need to keep digging and poking until you find the right answer.

Thanks for the answer you were right. The problem disappeared after reinstalling nmap with windows disabling “Support loopback traffic”