mirror of
https://github.com/ammaraskar/pyCraft.git
synced 2025-01-08 17:08:21 +01:00
27 lines
964 B
Python
27 lines
964 B
Python
|
import urllib2, urllib
|
||
|
|
||
|
def loginToMinecraft(username, password):
|
||
|
try:
|
||
|
url = 'https://login.minecraft.net'
|
||
|
header = {'Content-Type' : 'application/x-www-form-urlencoded'}
|
||
|
data = {'user' : username,
|
||
|
'password' : password,
|
||
|
'version' : '13'}
|
||
|
data = urllib.urlencode(data)
|
||
|
req = urllib2.Request(url, data, header)
|
||
|
opener = urllib2.build_opener()
|
||
|
response = opener.open(req)
|
||
|
response = response.read()
|
||
|
except urllib2.URLError:
|
||
|
toReturn = {'Response' : "Can't connect to minecraft.net"}
|
||
|
return toReturn
|
||
|
if(response == "Bad login"):
|
||
|
toReturn = {'Response' : "Incorrect username/password"}
|
||
|
return toReturn
|
||
|
response = response.split(":")
|
||
|
sessionid = response[3]
|
||
|
toReturn = {'Response' : "Good to go!",
|
||
|
'Username' : response[2],
|
||
|
'SessionID' : sessionid
|
||
|
}
|
||
|
return toReturn
|