Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sabnzbd / Mattermost error: "module named ssl_match_hostname" #27

Closed
seanvree opened this issue Aug 17, 2017 · 16 comments
Closed

Sabnzbd / Mattermost error: "module named ssl_match_hostname" #27

seanvree opened this issue Aug 17, 2017 · 16 comments
Assignees
Labels

Comments

@seanvree
Copy link

OS: Windows 10E x64
Sabnzbd: 2.1.0 [443efb5]

Not sure what changed, but the notifications just stopped working with MassterMost.

SABnzbd Notification settings:

mmosts://sabnzbd@mydomain.com/ifeaht4hpt89mrijxdpwxxxxxx?verify=False


ERROR a few seconds ago Notification script returned exit code 1 and output "Traceback (most recent call last):   File "C:\Program Files\SABnzbd\scripts\Notify.py", line 315, in      from pnotify import *   File "C:\Program Files\SABnzbd\scripts\Notify\pnotify\__init__.py", line 26, in      from NotifyBoxcar import NotifyBoxcar   File "C:\Program Files\SABnzbd\scripts\Notify\pnotify\NotifyBoxcar.py", line 23, in      import requests   File "C:\Program Files\SABnzbd\scripts\Notify\requests\__init__.py", line 58, in      from . import utils   File "C:\Program Files\SABnzbd\scripts\Notify\requests\utils.py", line 30, in      from .exceptions import InvalidURL   File "C:\Program Files\SABnzbd\scripts\Notify\requests\exceptions.py", line 10, in      from urllib3.exceptions import HTTPError as BaseHTTPError   File "C:\Program Files\SABnzbd\scripts\Notify\urllib3\__init__.py", line 10, in      from .connectionpool import (   File "C:\Program Files\SABnzbd\scripts\Notify\urllib3\connectionpool.py", line 35, in      from backports.ssl_match_hostname import CertificateError ImportError: No module named ssl_match_hostname "

Screenshot:

image

@caronc
Copy link
Owner

caronc commented Aug 17, 2017

I don't really see the problem, the error it's failing on is already present.
Did something else change before this error occurred? Did you update anything else?

@seanvree
Copy link
Author

@caronc - the problem is that it won't send notifications to MM anymore.

Umm, hard to say if anything updated, it's a headless box and updates software all the time but NO, Sab and MM were not udpated.

@caronc
Copy link
Owner

caronc commented Aug 18, 2017

You've stumped me on this one. The library it's looking for is in the Notify directory. Can you try checking out the master branch again?

Or even better yet, use the last stable release? That will at least force your content to get replaced and filled (if anything is missing).

l can't say with absolute certainty, but it would really appear like something got clobbered in your environment.

@seanvree
Copy link
Author

@caronc - Okay, I pulled .6.1 - still same error.

I mean, if something got "clobbered" then it must be a dependency that only SAB and/or this script uses because everything else is working fine on the box to include Mattermost and all the other apps that also send notifications to MM. Ie, Sonarr, Radarr, Headphones. Everything else works.

Wasn't there a debug arg I could run manually?

@caronc
Copy link
Owner

caronc commented Aug 18, 2017

Sure, you could try running the tool from the command line.

# Notify script by itself (-D is debug mode)
python Notify.py  -D -t "Test Title" -b "Test Body" -s mmost://your/url/here

# SABnzbd wrapper
python sabnzbd-notify.py complete 'Hello' 'World' mmost://your/url/here

But what you just stated in your last response is the weirdest part of this whole thing. It's failing on the version that I added the MattersMost feature for you :). It's the version that you left happy on (heh). That's why it just appears that something strange is going on on your side. I can't reproduce your error at all because it always successfully imports the backport module. I wonder if there is another module called 'backport' that is conflicting in your environment... hmm..

@seanvree
Copy link
Author

seanvree commented Aug 19, 2017

@caronc -

yeah, I don't doubt that it's something strange on my side, I just cant' figure it out. It looks like a SSL issue, but that doesn't make sense as I haven't touched my certs in months, and I know they are still good

C:\Sabnzbd\nzb-notify>python Notify.py  -D -t "Test Title" -b "Test Body" -s mmosts://sabnzbd@domain.com/ifeaht4xxxxxrijxdpwfia8ih?verify=False
Traceback (most recent call last):
  File "Notify.py", line 315, in <module>
    from pnotify import *
  File "C:\Sabnzbd\nzb-notify\Notify\pnotify\__init__.py", line 26, in <module>
    from NotifyBoxcar import NotifyBoxcar
  File "C:\Sabnzbd\nzb-notify\Notify\pnotify\NotifyBoxcar.py", line 23, in <module>
    import requests
  File "C:\Sabnzbd\nzb-notify\Notify\requests\__init__.py", line 58, in <module>
    from . import utils
  File "C:\Sabnzbd\nzb-notify\Notify\requests\utils.py", line 30, in <module>
    from .exceptions import InvalidURL
  File "C:\Sabnzbd\nzb-notify\Notify\requests\exceptions.py", line 10, in <module>
    from urllib3.exceptions import HTTPError as BaseHTTPError
  File "C:\Sabnzbd\nzb-notify\Notify\urllib3\__init__.py", line 10, in <module>
    from .connectionpool import (
  File "C:\Sabnzbd\nzb-notify\Notify\urllib3\connectionpool.py", line 35, in <module>
    from backports.ssl_match_hostname import CertificateError
ImportError: No module named ssl_match_hostname

C:\Sabnzbd\nzb-notify>python sabnzbd-notify.py complete 'Hello' 'World' mmosts://sabnzbd@domain.com/ifeahxxxxx9mrijxdpwfia8ih?verify=False
Traceback (most recent call last):
  File "C:\Sabnzbd\nzb-notify\Notify.py", line 315, in <module>
    from pnotify import *
  File "C:\Sabnzbd\nzb-notify\Notify\pnotify\__init__.py", line 26, in <module>
    from NotifyBoxcar import NotifyBoxcar
  File "C:\Sabnzbd\nzb-notify\Notify\pnotify\NotifyBoxcar.py", line 23, in <module>
    import requests
  File "C:\Sabnzbd\nzb-notify\Notify\requests\__init__.py", line 58, in <module>
    from . import utils
  File "C:\Sabnzbd\nzb-notify\Notify\requests\utils.py", line 30, in <module>
    from .exceptions import InvalidURL
  File "C:\Sabnzbd\nzb-notify\Notify\requests\exceptions.py", line 10, in <module>
    from urllib3.exceptions import HTTPError as BaseHTTPError
  File "C:\Sabnzbd\nzb-notify\Notify\urllib3\__init__.py", line 10, in <module>
    from .connectionpool import (
  File "C:\Sabnzbd\nzb-notify\Notify\urllib3\connectionpool.py", line 35, in <module>
    from backports.ssl_match_hostname import CertificateError
ImportError: No module named ssl_match_hostname

C:\Sabnzbd\nzb-notify>

@caronc
Copy link
Owner

caronc commented Aug 20, 2017

Make sure to change your password (or at least edit your previous post and scramble some of your details) when we're done here. I just sent a test message to your server by copying and pasting what you provided (i think).

Still can't reproduce your issue at all. Do you see a C:\Sabnzbd\nzb-notify\Notify\backports/ssl_match_hostname/__init__.py directory at all? It almost seems like it's missing for you. Make sure if the file is present, it's not zero bytes.

Did you install another addon recently? It's possible there is another backports module/directory on your device that is over-riding the one provided.

Another thing you could try (just to see if you can even import the module yourself is:

# Start up an instance of python this way (setting a path first - the same
# path the notify script does):
export PYTHONPATH="C:\Sabnzbd\nzb-notify\Notify"

# Or if doing from windows:
set PYTHONPATH="C:\Sabnzbd\nzb-notify\Notify"

# now start up python
python

Then from within python type:

from backports.ssl_match_hostname import CertificateError
# Hopefully you don't get an error doing this

Another thing you could try is deleting the Notify module complete (everything) and just checking out a brand new copy (if you hadn't already). The only thing this will do is ensure you're starting with no .pyc and/or .pyo files that may or may not be causing you issues. It will force them to get recreated.

Alternatively, you could just make ssl_match_hostname globally available to your device:
pip install backports.ssl_match_hostname

Good luck!

@seanvree
Copy link
Author

@caronc - you scared me for a second...I was like WTF did that come from.

So I have good news:

SIMPLE fix:

pip install backports.ssl_match_hostname

BAM. All good, not sure what changed, but that did it. Might wanna update your dependencies or something, might have just been me, but I have no idea what updated or why it stopped working.

THANKS!

@Safihre
Copy link
Contributor

Safihre commented Oct 9, 2017

@caronc I am also getting this error when downloading the zip and just setting it as SABnzbd Notification Script. I guess I could pip install it, but shouldn't it work out of the box?

  File "C:\Users\userv\Documents\GitHub\tests\nzb-notify-master\Notify.py", line 334, in <module>
    from pnotify import *
  File "C:\Users\userv\Documents\GitHub\tests\nzb-notify-master\Notify\pnotify\__init__.py", line 26, in <module>
    from .NotifyBoxcar import NotifyBoxcar
  File "C:\Users\userv\Documents\GitHub\tests\nzb-notify-master\Notify\pnotify\NotifyBoxcar.py", line 23, in <module>
    import requests
  File "C:\Users\userv\Documents\GitHub\tests\nzb-notify-master\Notify\requests\__init__.py", line 58, in <module>
    from . import utils
  File "C:\Users\userv\Documents\GitHub\tests\nzb-notify-master\Notify\requests\utils.py", line 30, in <module>
    from .exceptions import InvalidURL
  File "C:\Users\userv\Documents\GitHub\tests\nzb-notify-master\Notify\requests\exceptions.py", line 10, in <module>
    from urllib3.exceptions import HTTPError as BaseHTTPError
  File "C:\Users\userv\Documents\GitHub\tests\nzb-notify-master\Notify\urllib3\__init__.py", line 10, in <module>
    from .connectionpool import (
  File "C:\Users\userv\Documents\GitHub\tests\nzb-notify-master\Notify\urllib3\connectionpool.py", line 35, in <module>
    from backports.ssl_match_hostname import CertificateError
ImportError: No module named ssl_match_hostname

And:

~\Documents\GitHub\tests\nzb-notify-master\Notify> python
Python 2.7.14rc1 (v2.7.14rc1:c707893, Aug 27 2017, 00:09:00) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from backports.ssl_match_hostname import CertificateError
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named ssl_match_hostname
>>>

Works in Python 3.6 though:

~\Documents\GitHub\tests\nzb-notify-master\Notify> py
Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from backports.ssl_match_hostname import CertificateError
>>>

@caronc caronc reopened this Oct 9, 2017
@caronc caronc self-assigned this Oct 9, 2017
@caronc caronc added the bug label Oct 9, 2017
@seanvree
Copy link
Author

seanvree commented Oct 9, 2017

FYI, MM notifications are still working for me.

@caronc
Copy link
Owner

caronc commented Oct 9, 2017

FYI, MM notifications are still working for me.

@seanvree, but you used pip install to fix your problem; we kind of just buried it with that workaround 😉. @Safihre has a point: there is simply no reason why this archive shouldn't just work out of the box (without having to install the extra packaging that you did).

But now with respect to the issue:
@Safihre: This script definitely won't work with Python 3.6; i haven't ported any of the code yet. By chance, are you also using Microsoft Windows when you get this error? I still can't reproduce it. ☹️

I just created a simple docker image with a plain-jane OS and it works for me. Here is what i did:

# A Simple CentOS image:
docker pull centos
 
# Run the instance
docker run -i -t centos /bin/bash

# Inside the docker instance:
# I installed wget and unzip (since it isn't already available)
yum install wget unzip -y

# Python is included, but backports is not:
rpm -qa | egrep -i backports; echo $?
1

# Launch latest NZB-Notify
wget https://github.com/caronc/nzb-notify/archive/master.zip
unzip master.zip 
nzb-notify-master/Notify.py -D -s mmosts://myuser@domain.com/auth?verify=False
# It gracefully returns (as I'd want it to)

I'll wait back to hear on what you're environment is.

@Safihre
Copy link
Contributor

Safihre commented Oct 9, 2017

Windows 10!

@caronc
Copy link
Owner

caronc commented Oct 9, 2017

Well... i found the problem, but i don't know what the fix is yet. Python 2.7.13 defaults it's install into C:\Python27. It creates several subdirectories within this; one of which is C:\Python27\lib\site-packages\backports. So just out of the box (without this script installed):

import backports
print(backports.__path__)
# C:\Python27\lib\site-packages\backports

It appears the windows install of Python ignores the first few lines of the Notify.py script which forces the path to search our Notify directory first (wherever it is):

import sys
from os.path import join
from os.path import abspath
from os.path import dirname

sys.path.insert(0, join(dirname(abspath(__file__)), 'Notify'))

In windows this is definitely broken; because when i revisit the first block of code (ran from the same directory the Notify.py and Notify directory are in):

import sys
from os import getcwd
from os.path import join
sys.path.insert(0, join(getcwd(), 'Notify'))

# Now if we import backports, we should find the one in our Notify directory
import backports
print(backports.__path__)    # Nope... :(
# C:\Python27\lib\site-packages\backports

# What's weird is it's not entirely broken... you can do the following:
import chardet
print(chardet.__path__)
# Prints my path to Notify/chardet

What's really weird, is (in Windows) even if i delete the C:\Python27\lib\site-packages\backports, it still imports the module; so it's like part of the Python27 build in some way. Alternatively (as we already know) pip install works because it drops the correct package in this site-packages\backports directory.

So basically, the Microsoft version of Python27 can't seem to stop referencing (even when told not to) the backports location.

@caronc
Copy link
Owner

caronc commented Oct 9, 2017

I created a ticket with Python's bug tracker which will hopefully either have some guy call me an idiot and point out what I'm missing here. Or alternatively; maybe this really is a bug and it can get fixed upstream 😄.

@caronc
Copy link
Owner

caronc commented Oct 13, 2017

So Python dev's closed the ticket and pointed out that the configparser (installed with pip) is what is monkeying around with the backports module.

So if you can't beat em, join em. Renaming backports to _backports (and changing all references) should bypass the problem since the keyword (backports) is clearly reserved.

@caronc
Copy link
Owner

caronc commented Oct 18, 2017

I'm going to close this ticket as I'm confident that renaming the backports directory should stop windows environments from ignoring it's contents.

Feel free to let me know if you're still hindered; I'll gladly re-open the ticket and keep digging! 🕳

@caronc caronc closed this as completed Oct 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants