iredmail / iRedMail

Full-featured, open source mail server solution for mainstream Linux/BSD distributions.

Home Page:https://www.iredmail.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

iredapd Unexpected error: AttributeError("'NoneType' object has no attribute 'connect'"

kman261 opened this issue · comments

REQUIRED BASIC INFO OF YOUR IREDMAIL SERVER:

  • iRedMail version (check /etc/iredmail-release): 1.6.8
  • Deployed with iRedMail Easy or the downloadable installer? No
  • Linux/BSD distribution name and version: Rocky Linux 9
  • Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
  • Web server (Apache or Nginx): Nginx
  • Manage mail accounts with iRedAdmin-Pro? No
  • [IMPORTANT] Related original log or error message is required if you're experiencing an issue.

New installation with migration from old Centos 7 box.

While trying to figure out why Outlook desktop is not sending calendar events to SOGo, but it receives them, I was looking through the logs. I am seeing this error in iredapd
"iredapd Unexpected error: AttributeError("'NoneType' object has no attribute 'connect'"

Mar 22 05:22:29 mx python3[285070]: iredapd Unexpected error: AttributeError("'NoneType' object has no attribute 'connect'"). 
Fallback to default action: DUNNO 
Mar 22 05:22:29 mx python3[285070]: iredapd Session ended.
Mar 22 05:22:29 mx python3[285070]: iredapd [136.147.178.131] END-OF-MESSAGE, bounce-20_html-267662848-345489-7209300-3118@bounce.email.example.com -> kman261@example2.com, DUNNO [recipient_count=1, size=70245, process_time=0.0001s]
Mar 22 05:22:29 mx python3[285070]: iredapd [SQL] Insert into smtp_sessions: #012        INSERT INTO smtp_sessions (#012            time, time_num,#012            action, reason, instance,#012            client_address, client_name, reverse_client_name, helo_name,#012            encryption_protocol, encryption_cipher,#012            server_address, server_port,#012            sender, sender_domain,#012            sasl_username, sasl_domain,#012            recipient, recipient_domain)#012        VALUES (#012            '2024-03-22 11:22:29', 1711106549,#012            'DUNNO', ''    ...

I restarted iredapd in debug mode and got:

Mar 22 07:14:09 mx python3[684463]: iredapd Error while creating SQL connection: ModuleNotFoundError("No module named 'pymysql'")
Mar 22 07:14:09 mx python3[684463]: iredapd Error while creating SQL connection: ModuleNotFoundError("No module named 'pymysql'")
Mar 22 07:14:09 mx python3[684463]: iredapd Error while creating SQL connection: ModuleNotFoundError("No module named 'pymysql'")
Mar 22 07:14:09 mx python3[684463]: iredapd Starting iRedAPD (version: 5.3.3, backend: mysql), listening on 127.0.0.1:7777.
Mar 22 07:14:09 mx python3[684463]: iredapd Loading plugin (priority: 100): reject_null_sender
Mar 22 07:14:09 mx python3[684463]: iredapd Loading plugin (priority: 99): wblist_rdns
Mar 22 07:14:09 mx python3[684463]: iredapd Loading plugin (priority: 90): reject_sender_login_mismatch
Mar 22 07:14:09 mx python3[684463]: iredapd Loading plugin (priority: 80): greylisting
Mar 22 07:14:09 mx python3[684463]: iredapd Loading plugin (priority: 60): throttle
Mar 22 07:14:09 mx python3[684463]: iredapd Loading plugin (priority: 51): sql_ml_access_policy
Mar 22 07:14:09 mx python3[684463]: iredapd Loading plugin (priority: 50): sql_alias_access_policy
Mar 22 07:14:09 mx python3[684463]: iredapd Loading plugin (priority: 40): amavisd_wblist
Mar 22 07:14:09 mx python3[684463]: iredapd Starting SRS sender rewriting channel, listening on 127.0.0.1:7778
Mar 22 07:14:09 mx python3[684463]: iredapd Starting SRS recipient rewriting channel, listening on 127.0.0.1:7779

Find pymysql:

[root@mx iredapd]# find / -name pymysql*
/usr/lib64/python3.9/site-packages/sqlalchemy/dialects/mysql/__pycache__/pymysql.cpython-39.opt-1.pyc
/usr/lib64/python3.9/site-packages/sqlalchemy/dialects/mysql/__pycache__/pymysql.cpython-39.pyc
/usr/lib64/python3.9/site-packages/sqlalchemy/dialects/mysql/pymysql.py
[root@mx iredapd]#
[root@mx iredapd]# python --version
Python 3.9.18

New installation with migration from old Centos 7 box.

Please download the latest iRedAPD release and upgrade (no matter which iRedAPD version you're running), so that it can install required Python modules on your server.
https://docs.iredmail.org/upgrade.iredapd.html

Also upgrade mlmmjadmin:
https://docs.iredmail.org/upgrade.mlmmjadmin.html

Unfortunately, it did not fix the problem. I upgraded iRedApd, but still have the error.
Upgrade:

[root@mx tools]# bash upgrade_iredapd.sh
* Detected Linux/BSD distribution: RHEL
* Checking dependent Python modules:
  + [required] wheel
  + [required] sqlalchemy
  + [required] dnspython
  + [required] requests
Install packages: python3-PyMySQL
Last metadata expiration check: 2:08:12 ago on Sun Mar 24 05:19:28 2024.
Package python3-PyMySQL-0.10.1-6.el9.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!
* Found iRedAPD directory: /opt/iredapd, symbol link of iRedAPD-5.3.3
* Found iRedAPD config file: /opt/iredapd/settings.py
* Add new SQL tables - if there's any
* Copying new version to /opt/iRedAPD-5.3.3
* Copy old config file: settings.py (/opt/iredapd/settings.py -> /opt/iRedAPD-5.3.3/settings.py)
cp: '/opt/iredapd/settings.py' and '/opt/iRedAPD-5.3.3/settings.py' are the same file
* Copy custom plugins: iRedAPD-5.3.3/plugins/custom_*.py.
* Set correct owner and permission for /opt/iRedAPD-5.3.3: root:root, 0500.
* Set permission for iRedAPD config file: /opt/iRedAPD-5.3.3/settings.py -> 0400.
* Re-create symbol link: /opt/iredapd -> /opt/iRedAPD-5.3.3
* Remove existing systemd service files.
* Copy systemd service file: /opt/iredapd/rc_scripts/iredapd.service -> /lib/systemd/system/iredapd.service.
Created symlink /etc/systemd/system/multi-user.target.wants/iredapd.service -> /usr/lib/systemd/system/iredapd.service.
Redirecting to /bin/systemctl restart rsyslog.service
* Replace py2 by py3 in cron jobs.
* Restarting iRedAPD service.
Redirecting to /bin/systemctl restart iredapd.service
* Upgrade completed.

< NOTE > If iRedAPD doesn't work as expected, please post your issue in our
< NOTE > online support forum: http://www.iredmail.org/forum/
< NOTE >
< NOTE > * Turn on debug mode: http://www.iredmail.org/docs/debug.iredapd.html
< NOTE > * iRedAPD log file is /var/log/iredapd/iredapd.log.

Restarting iRedApd:
[root@mx tools]# service iredapd restart
Redirecting to /bin/systemctl restart iredapd.service

Log during restart

Mar 24 07:29:03 mx python3[880411]: iredapd Error while creating SQL connection: ModuleNotFoundError("No module named 'pymysql'")
Mar 24 07:29:03 mx python3[880411]: iredapd Error while creating SQL connection: ModuleNotFoundError("No module named 'pymysql'")
Mar 24 07:29:03 mx python3[880411]: iredapd Error while creating SQL connection: ModuleNotFoundError("No module named 'pymysql'")
Mar 24 07:29:03 mx python3[880411]: iredapd Starting iRedAPD (version: 5.3.3, backend: mysql), listening on 127.0.0.1:7777.
Mar 24 07:29:03 mx python3[880411]: iredapd Loading plugin (priority: 100): reject_null_sender
Mar 24 07:29:03 mx python3[880411]: iredapd Loading plugin (priority: 99): wblist_rdns
Mar 24 07:29:03 mx python3[880411]: iredapd Loading plugin (priority: 90): reject_sender_login_mismatch
Mar 24 07:29:03 mx python3[880411]: iredapd Loading plugin (priority: 80): greylisting
Mar 24 07:29:03 mx python3[880411]: iredapd Loading plugin (priority: 60): throttle
Mar 24 07:29:03 mx python3[880411]: iredapd Loading plugin (priority: 51): sql_ml_access_policy
Mar 24 07:29:03 mx python3[880411]: iredapd Loading plugin (priority: 50): sql_alias_access_policy
Mar 24 07:29:03 mx python3[880411]: iredapd Loading plugin (priority: 40): amavisd_wblist
Mar 24 07:29:03 mx python3[880411]: iredapd Starting SRS sender rewriting channel, listening on 127.0.0.1:7778
Mar 24 07:29:03 mx python3[880411]: iredapd Starting SRS recipient rewriting channel, listening on 127.0.0.1:7779

A little later:

Mar 24 08:00:10 mx python3[880415]: iredapd Unexpected error: AttributeError("'NoneType' object has no attribute 'connect'"). Fallback to default action: DUNNO
Mar 24 08:00:10 mx python3[880415]: iredapd Session ended.


What's the output of command below?

python3 -c "import pymysql; print(pymysql.__version__)"

[root@mx ~]# python3 -c "import pymysql; print(pymysql.version)"

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'pymysql'

[root@mx ~]#

Ok, I ran
pip install pymysql

and now the command returns
1.4.6

I restarted iredapd and the error is gone.