Repository: pymedusa/Medusa

Issue:
TypeError: cafile must be None or a byte string?
### Before submitting your issue:

Enable debug logging in Medusa settings, reproduce the error (be sure to disable after the bug is fixed)

Branch/Commit: Latest (Saturday 29th Oct)
OS: Debian Linux (FeralHosting Seedbox)
What you did: Updated to the latest commit
What happened: Medusa won't run - spits out this log (below)
What you expected: For it to run
Logs:

```
 python ~/.sickrage/SickBeard.py -d -p 10101
Traceback (most recent call last):
  File "/media/sdq1/home/whipcracker/.sickrage/SickBeard.py", line 9, in <module>
    from start import Application
  File "/media/sdq1/home/whipcracker/.sickrage/start.py", line 104, in <module>
    from medusa.server.core import AppWebServer
  File "/media/sdq1/home/whipcracker/.sickrage/medusa/server/core.py", line 17, in <module>
    from .web import CalendarHandler, KeyHandler, LoginHandler, LogoutHandler
  File "/media/sdq1/home/whipcracker/.sickrage/medusa/server/web/__init__.py", line 7, in <module>
    from .home import Home, HomeAddShows, HomeChangeLog, HomeIRC, HomeNews, HomePostProcess
  File "/media/sdq1/home/whipcracker/.sickrage/medusa/server/web/home/__init__.py", line 4, in <module>
    from .add_shows import HomeAddShows
  File "/media/sdq1/home/whipcracker/.sickrage/medusa/server/web/home/add_shows.py", line 29, in <module>
    from ....show.recommendations.trakt import TraktPopular
  File "/media/sdq1/home/whipcracker/.sickrage/medusa/show/recommendations/trakt.py", line 170, in <module>
    tvdb_api_v2 = get_tvdbv2_api()
  File "/media/sdq1/home/whipcracker/.sickrage/medusa/show/recommendations/trakt.py", line 41, in get_tvdbv2_api
    access_token = auth_api.login_post(authentication_string)
  File "/media/sdq1/home/whipcracker/.sickrage/lib/tvdbapiv2/apis/authentication_api.py", line 124, in login_post
    callback=params.get('callback'))
  File "/media/sdq1/home/whipcracker/.sickrage/lib/tvdbapiv2/api_client.py", line 324, in call_api
    response_type, auth_settings, callback)
  File "/media/sdq1/home/whipcracker/.sickrage/lib/tvdbapiv2/api_client.py", line 150, in __call_api
    post_params=post_params, body=body)
  File "/media/sdq1/home/whipcracker/.sickrage/lib/tvdbapiv2/api_client.py", line 360, in request
    body=body)
  File "/media/sdq1/home/whipcracker/.sickrage/lib/tvdbapiv2/rest.py", line 208, in POST
    body=body)
  File "/media/sdq1/home/whipcracker/.sickrage/lib/tvdbapiv2/rest.py", line 143, in request
    headers=headers)
  File "/media/sdq1/home/whipcracker/.sickrage/lib/requests/packages/urllib3/request.py", line 73, in request
    **urlopen_kw)
  File "/media/sdq1/home/whipcracker/.sickrage/lib/requests/packages/urllib3/request.py", line 151, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "/media/sdq1/home/whipcracker/.sickrage/lib/requests/packages/urllib3/poolmanager.py", line 165, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "/media/sdq1/home/whipcracker/.sickrage/lib/requests/packages/urllib3/connectionpool.py", line 578, in urlopen
    chunked=chunked)
  File "/media/sdq1/home/whipcracker/.sickrage/lib/requests/packages/urllib3/connectionpool.py", line 351, in _make_request
    self._validate_conn(conn)
  File "/media/sdq1/home/whipcracker/.sickrage/lib/requests/packages/urllib3/connectionpool.py", line 814, in _validate_conn
    conn.connect()
  File "/media/sdq1/home/whipcracker/.sickrage/lib/requests/packages/urllib3/connection.py", line 289, in connect
    ssl_version=resolved_ssl_version)
  File "/media/sdq1/home/whipcracker/.sickrage/lib/requests/packages/urllib3/contrib/pyopenssl.py", line 328, in ssl_wrap_socket
    ctx.load_verify_locations(ca_certs, ca_cert_dir)
  File "/usr/lib/python2.7/dist-packages/OpenSSL/SSL.py", line 303, in load_verify_locations
    raise TypeError("cafile must be None or a byte string")
TypeError: cafile must be None or a byte string

```

I've tried deleting the folder and tried a new git clone, but I have the same issue. Never been a problem until the new update. Hope someone can help!



Discussion:
Are you able to report which PyOpenSSL version you have installed in your system?

If you have pip installed you can just: `pip show pyopenssl`

```
---
Metadata-Version: 1.1
Name: pyOpenSSL
Version: 16.1.0
```

I believe it might be related with an old python-openssl version: https://github.com/pimutils/vdirsyncer/issues/258

If you have a debian-based system you could try to simulate the package installation to check the version:

```
 sudo apt-get -s install python-openssl


Conf python-openssl (0.14-1 Debian:8.6/stable [all])
```

The version 0.14-1 is the problematic one

Hey lads, thanks for the quick reply!

Running
Name: pyOpenSSL
Version: 0.14
Location: /usr/lib/python2.7/dist-packages
Requires: cryptography, six

what's the easiest way to update  please?

We have a dedicated page for SSL issues:

https://github.com/pymedusa/Medusa/wiki/SSL-Errors

Apart from that, we still need to fix this issue since it shouldn't stop Medusa from booting.

No worries then... will see if I can update pyOpenSSL using pip (once I upload the directory back to the seedbox) and will see if it works from there :)

Just realised I need root access on the seedbox to allow this update, so unsure if I can fix this or not. Would be great if you could please figure a way to get this working with 0.14 instead and I could just git clone back in maybe?

If I can run this without using HTTPS... which part of the config file should I edit to allow it to run in normal HTTP mode instead temporarily?


Resolving patch:
diff --git a/medusa/show/recommendations/trakt.py b/medusa/show/recommendations/trakt.py
--- a/medusa/show/recommendations/trakt.py
+++ b/medusa/show/recommendations/trakt.py
@@ -59,6 +59,7 @@ def __init__(self):
         self.recommender = "Trakt Popular"
         self.default_img_src = 'trakt-default.png'
         self.anidb = Anidb(cache_dir=app.CACHE_DIR)
+        self.tvdb_api_v2 = get_tvdbv2_api()
 
     def _create_recommended_show(self, show_obj):
         """Create the RecommendedShow object from the returned showobj."""
@@ -78,7 +79,7 @@ def _create_recommended_show(self, show_obj):
         use_default = None
         image = None
         try:
-            image = tvdb_api_v2.series_id_images_query_get(show_obj['show']['ids']['tvdb'], key_type='poster').data[0].file_name
+            image = self.tvdb_api_v2.series_id_images_query_get(show_obj['show']['ids']['tvdb'], key_type='poster').data[0].file_name
         except Exception:
             use_default = self.default_img_src
             logger.log('Missing poster on TheTVDB for show %s' % (show_obj['show']['title']), logger.DEBUG)
@@ -167,5 +168,3 @@ def fetch_popular_shows(self, page_url=None, trakt_list=None):  # pylint: disabl
             raise
 
         return blacklist, trending_shows, removed_from_medusa
-
-tvdb_api_v2 = get_tvdbv2_api()


Test patch: