forked from rickatnight11/collectd-plex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_auth_token.py
executable file
·33 lines (27 loc) · 1.02 KB
/
get_auth_token.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
import httplib, urllib, base64, socket, getpass, json
# Grab user credentials
username = raw_input("plex.tv User: ")
password = getpass.getpass("plex.tv Password: ")
# Form HTTP request
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
txdata = ""
headers={'Authorization': "Basic %s" % base64string,
'X-Plex-Device': "CollectD Plex Plugin",
'X-Plex-Device-Name': socket.gethostname(),
'X-Plex-Client-Identifier': "collectd-plex"+socket.gethostname(),
'X-Plex-Product': "CollectD Plex Plugin",
'X-Plex-Version': "0.001"}
# Make HTTP request to plex.tv
conn = httplib.HTTPSConnection("plex.tv")
conn.request("POST","/users/sign_in.json",txdata,headers)
response = conn.getresponse()
data = response.read()
# Check response
if response.status != 201:
print "HTTP Error: " + str(response.status)
print str(data)
else:
j = json.loads(str(data))
print "Plex.tv Auth Token: " + j['user']['authentication_token']
conn.close()