ImportError: No module named client.csocket
macgeneral opened this issue · 3 comments
Running the script I get the following output:
Traceback (most recent call last):
File "./blocklist.py", line 14, in
from client.csocket import CSocket
ImportError: No module named client.csocket
System:
Python 2.7.5 on CentOS Linux release 7.2.1511 (Core)
Am I missing any requirements (or is the script for Windows only)?
Hi macgeneral,
no, this script is rather Linux only and expects the fail2ban modules in /usr/share/fail2ban. The CSocket module is one of the modules supplied by fail2ban. Could you please check where your installation puts these modules? You can modify line 11 accordingly.
Thank you for the fast reply.
I have fail2ban 0.10 from https://github.com/fail2ban/fail2ban installed which puts all the required modules in:
/usr/lib/python2.7/site-packages/fail2ban/
when replacing the path in line 11 with:
sys.path.insert(1, "/usr/lib/python2.7/site-packages/fail2ban/")
I get:
Traceback (most recent call last):
File "blocklist.py", line 15, in
from client.csocket import CSocket
File "/usr/lib/python2.7/site-packages/fail2ban/client/csocket.py", line 29, in
from ..protocol import CSPROTO
ValueError: Attempted relative import beyond toplevel package
But commenting it out and adding a fail2ban in line 14 works (propably the cleaner solution than adding a sys path - I'm just not sure if it will work on standard configurations):
from fail2ban.client.csocket import CSocket
:)
If fail2ban installs in the default Path (/usr/lib/pythonX.X/site-packages/
) then yes, this would be the cleaner path.
Unfortunately this is not always the case. I'll check if there is a better solution that works for all parties concerned.