Fix HTTP 401 and authentication endless loop

This commit is contained in:
tomkat83 2016-04-07 16:10:07 +02:00
parent ae51e43145
commit 753e090cec
4 changed files with 26 additions and 1 deletions

View file

@ -474,7 +474,7 @@ def GetPMSStatus(token):
"""
answer = {}
xml = downloadutils.DownloadUtils().downloadUrl(
"{server}" + '/status/sessions',
'{server}/status/sessions',
type="GET",
headerOptions={'X-Plex-Token': token})
try:

View file

@ -5,6 +5,8 @@
import requests
import xml.etree.ElementTree as etree
import xbmcgui
from utils import logging, settings, window
import clientinfo
@ -245,6 +247,27 @@ class DownloadUtils():
# No body in the response
return True
elif r.status_code == 401:
r.encoding = 'utf-8'
self.logMsg('HTTP error 401 from PMS. Message received:', -1)
self.logMsg(r.text, -1)
if '401 Unauthorized' in r.text:
# Truly unauthorized
self.logMsg('We seem to be truely unauthorized', 0)
if window('emby_serverStatus') not in ('401', 'Auth'):
# Tell userclient token has been revoked.
self.logMsg('Setting emby_serverStatus to 401', 0)
window('emby_serverStatus', value="401")
xbmcgui.Dialog().notification(
self.addonName,
"Error connecting: Unauthorized.",
xbmcgui.NOTIFICATION_ERROR)
return 401
else:
# there might be other 401 where e.g. PMS is under strain (tbv)
self.logMsg('PMS might only be under strain', 0)
return 401
elif r.status_code in (200, 201):
# 200: OK
# 201: Created

View file

@ -253,6 +253,7 @@ class UserClient(threading.Thread):
lang(39023))
xbmc.executebuiltin(
'Addon.OpenSettings(plugin.video.plexkodiconnect)')
return False
# Get /profile/addon_data
addondir = xbmc.translatePath(

View file

@ -39,6 +39,7 @@ class WebSocket(threading.Thread):
self.logMsg(message, -1)
return False
self.logMsg('websocket message received: %s' % message, -1)
# Triage
typus = message.get('type')
if typus is None: