{"action":"created","issue":{"url":"https://api.github.com/repos/iBaa/PlexConnect/issues/341","labels_url":"https://api.github.com/repos/iBaa/PlexConnect/issues/341/labels{/name}","comments_url":"https://api.github.com/repos/iBaa/PlexConnect/issues/341/comments","events_url":"https://api.github.com/repos/iBaa/PlexConnect/issues/341/events","html_url":"https://github.com/iBaa/PlexConnect/issues/341","id":70464334,"number":341,"title":"SSL Cert Verification Error When Logging into MyPlex","user":{"login":"conallob","id":7395717,"avatar_url":"https://avatars.githubusercontent.com/u/7395717?v=3","gravatar_id":"","url":"https://api.github.com/users/conallob","html_url":"https://github.com/conallob","followers_url":"https://api.github.com/users/conallob/followers","following_url":"https://api.github.com/users/conallob/following{/other_user}","gists_url":"https://api.github.com/users/conallob/gists{/gist_id}","starred_url":"https://api.github.com/users/conallob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/conallob/subscriptions","organizations_url":"https://api.github.com/users/conallob/orgs","repos_url":"https://api.github.com/users/conallob/repos","events_url":"https://api.github.com/users/conallob/events{/privacy}","received_events_url":"https://api.github.com/users/conallob/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-04-23T17:15:54Z","updated_at":"2015-12-16T20:12:09Z","closed_at":null,"body":"When attempting to sign into my PlexPass account through PlexConnect, my AppleTV spins and spins and I see the following stack trace on my server running PlexConnect.\r\n\r\nStack Trace:\r\n\r\n16:24:32 WebServer: File Not Found:\r\nTraceback (most recent call last):\r\n  File \"/usr/local/taku/PlexConnect/WebServer.py\", line 229, in do_GET\r\n    XML = XMLConverter.XML_PMS2aTV(PMSaddress, self.path + query, options)\r\n  File \"/usr/local/taku/PlexConnect/XMLConverter.py\", line 241, in XML_PMS2aTV\r\n    (username, auth_token) = PlexAPI.MyPlexSignIn(parts[0], parts[1], options)\r\n  File \"/usr/local/taku/PlexConnect/PlexAPI.py\", line 583, in MyPlexSignIn\r\n    response = urlopener.open(request).read()\r\n  File \"/usr/local/lib/python2.7/urllib2.py\", line 431, in open\r\n    response = self._open(req, data)\r\n  File \"/usr/local/lib/python2.7/urllib2.py\", line 449, in _open\r\n    '_open', req)\r\n  File \"/usr/local/lib/python2.7/urllib2.py\", line 409, in _call_chain\r\n    result = func(*args)\r\n  File \"/usr/local/lib/python2.7/urllib2.py\", line 1240, in https_open\r\n    context=self._context)\r\n  File \"/usr/local/lib/python2.7/urllib2.py\", line 1197, in do_open\r\n    raise URLError(err)\r\nURLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)>\r\n\r\nOS: FreeBSD 10.1-STABLE\r\nPython Version: 2.7.9\r\n\r\nI suspect PlexAPI.py needs to be tweaked to allow for custom SSL settings, such as a bundled CA file. I'm more familiar with requests instead of urllib2, but https://docs.python.org/2/library/ssl.html#ssl.SSLContext.load_verify_locations in combination with the Mozilla CA cert (see the certifi wrapper - https://pypi.python.org/pypi/certifi/ ) would be a good start\r\n"},"comment":{"url":"https://api.github.com/repos/iBaa/PlexConnect/issues/comments/165231868","html_url":"https://github.com/iBaa/PlexConnect/issues/341#issuecomment-165231868","issue_url":"https://api.github.com/repos/iBaa/PlexConnect/issues/341","id":165231868,"user":{"login":"freestream","id":5450032,"avatar_url":"https://avatars.githubusercontent.com/u/5450032?v=3","gravatar_id":"","url":"https://api.github.com/users/freestream","html_url":"https://github.com/freestream","followers_url":"https://api.github.com/users/freestream/followers","following_url":"https://api.github.com/users/freestream/following{/other_user}","gists_url":"https://api.github.com/users/freestream/gists{/gist_id}","starred_url":"https://api.github.com/users/freestream/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/freestream/subscriptions","organizations_url":"https://api.github.com/users/freestream/orgs","repos_url":"https://api.github.com/users/freestream/repos","events_url":"https://api.github.com/users/freestream/events{/privacy}","received_events_url":"https://api.github.com/users/freestream/received_events","type":"User","site_admin":false},"created_at":"2015-12-16T20:12:09Z","updated_at":"2015-12-16T20:12:09Z","body":"@valyno I hope this helps you. I guess you have a different version than the one I have.\r\n\r\n**Line 33**\r\n```\r\nimport sys\r\nimport struct\r\nimport time\r\nimport urllib2, socket, StringIO, gzip\r\nfrom threading import Thread\r\nimport Queue\r\nimport ssl\r\n```\r\n\r\n**Line 362-405**\r\n```\r\ndef getXMLFromPMS(baseURL, path, options={}, authtoken='', enableGzip=False):\r\n    xargs = {}\r\n    if not options==None:\r\n        xargs = getXArgsDeviceInfo(options)\r\n    if not authtoken=='':\r\n        xargs['X-Plex-Token'] = authtoken\r\n\r\n    dprint(__name__, 1, \"URL: {0}{1}\", baseURL, path)\r\n    dprint(__name__, 1, \"xargs: {0}\", xargs)\r\n\r\n    request = urllib2.Request(baseURL+path , None, xargs)\r\n    request.add_header('User-agent', 'PlexConnect')\r\n    if enableGzip:\r\n        request.add_header('Accept-encoding', 'gzip')\r\n\r\n    try:\r\n        ssl._create_default_https_context = ssl._create_unverified_context\r\n        response = urllib2.urlopen(request, timeout=20)\r\n    except urllib2.URLError as e:\r\n        dprint(__name__, 0, 'No Response from Plex Media Server')\r\n        if hasattr(e, 'reason'):\r\n            dprint(__name__, 0, \"We failed to reach a server. Reason: {0}\", e.reason)\r\n        elif hasattr(e, 'code'):\r\n            dprint(__name__, 0, \"The server couldn't fulfill the request. Error code: {0}\", e.code)\r\n        return False\r\n    except IOError:\r\n        dprint(__name__, 0, 'Error loading response XML from Plex Media Server')\r\n        return False\r\n\r\n    if response.info().get('Content-Encoding') == 'gzip':\r\n        buf = StringIO.StringIO(response.read())\r\n        file = gzip.GzipFile(fileobj=buf)\r\n        XML = etree.parse(file)\r\n    else:\r\n        # parse into etree\r\n        XML = etree.parse(response)\r\n\r\n    dprint(__name__, 1, \"====== received PMS-XML ======\")\r\n    dprint(__name__, 1, XML.getroot())\r\n    dprint(__name__, 1, \"====== PMS-XML finished ======\")\r\n\r\n    #XMLTree = etree.ElementTree(etree.fromstring(response))\r\n\r\n    return XML\r\n```"}}