Okay, trying to avoid been locked out by the new fancy Home stuff, so thought I would register my little app @ plex.tv, by keep failing here :(
Code is like this:
#********** Get token from plex.tv *********
''' This will get a valid token, that can be used for authenticating if needed, or even better...inserted into the header '''
@route(PREFIX + '/getToken')
def getToken():
myUrl = 'https://plex.tv/users/sign_in.json'
userName = 'wiking@upnorth.dk'
userPwd = 'MyPaSSWord'
base64string = base64.encodestring('%s:%s' % (userName, userPwd)).replace('
', '')
MYAUTHHEADER= {}
MYAUTHHEADER['X-Plex-Product'] = 'TestChannel'
MYAUTHHEADER['X-Plex-Client-Identifier'] = '7608cf36-742b-11e4-8b39-00089bd210a2'
MYAUTHHEADER['X-Plex-Version'] = '1.0'
MYAUTHHEADER['Authorization'] = 'Basic ' + base64string
httpResponse = HTTP.Request(myUrl, values=None, headers=MYAUTHHEADER, immediate=True)
print httpResponse.content
And to save others some time, here's the final function:
#********** Get token from plex.tv *********
''' This will return a valid token, that can be used for authenticating if needed, to be inserted into the header '''
# DO NOT APPEND THE TOKEN TO THE URL...IT MIGHT BE LOGGED....INSERT INTO THE HEADER INSTEAD
@route(PREFIX + '/getToken')
def getToken(userName, userPwd):
myUrl = 'https://plex.tv/users/sign_in.json'
base64string = String.Encode('%s:%s' % (userName, userPwd)).replace('
', '')
MYAUTHHEADER= {}
MYAUTHHEADER['X-Plex-Product'] = NAME
MYAUTHHEADER['X-Plex-Client-Identifier'] = APPGUID
MYAUTHHEADER['X-Plex-Version'] = VERSION
MYAUTHHEADER['Authorization'] = 'Basic ' + base64string
DUMMYVALUE = {}
DUMMYVALUE['Barkley'] = 'IsAFineDog'
jsonResponse = JSON.ObjectFromURL(myUrl, headers=MYAUTHHEADER, values = DUMMYVALUE)
# print 'Token is : ' , jsonResponse['user']['authentication_token']
return jsonResponse['user']['authentication_token']
Cool, but above actually also works, and the sadly old pdf I use states:
String.Encode(s)
Encodes the given string using the framework’s standard encoding (a slight variant on
Base64 which ensures that the string can be safely used as part of a URL).
But guess your call leaves out any doubts, but was sadly, AFAIK, undocumented :huh:
You can also 'force' a post without (dummy) post values by setting method='POST' on the HTTP request:
Nice, and like the urllib2 version, and better, even though I love sending a "Barkley", he's an overhead, and no Elan....No prune was intended here, so will switch to Sanders methode :D
Regardless.....Thanks a bunch for the feedback, and feedback to Plex here is that we really need updated docs, so we can produce faster, and not create "barkley" overheads, when hammering on your doorstep for a token ;)
The difference between String.Encode and String.Base64Encode is that with String.Encode some characters are replaced with others to make it safe to pass the string as a GET parameter in URLs.