Skip to content

Instantly share code, notes, and snippets.

@jenrik
Last active May 19, 2020 07:31
Show Gist options
  • Save jenrik/5149944 to your computer and use it in GitHub Desktop.
Save jenrik/5149944 to your computer and use it in GitHub Desktop.
[DEPRECATED] Minecraft login script for Python 3. Use as you wish as long as you give me credit.
import http.client, urllib.parse, getpass
username = input("Username: ")
password = getpass.getpass(prompt='Password: ', stream=None)
params = urllib.parse.urlencode({'user': username, 'password': password, 'version': 12})
headers = {"Content-type": "application/x-www-form-urlencoded"}
conn = http.client.HTTPConnection("login.minecraft.net")
conn.request("POST", "", params, headers)
response = conn.getresponse()
print(response.status, response.reason)
data = response.read()
data = data.decode("utf-8").split(':')
print("Current minecraft version: " + data[0])
print("Minecraft username: " + data[2])
print("Session ID: " + data[3])
print("UID: " + data[4])
conn.close()
@shai
Copy link

shai commented May 17, 2020

Can you make this work and also post it with a fixed indentation?

Traceback (most recent call last):
  File "./mc2.py", line 7, in <module>
    conn.request("POST", "", params, headers)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1229, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1275, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1224, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1016, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 956, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 928, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 707, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 748, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

@jenrik
Copy link
Author

jenrik commented May 18, 2020

@shai The login protocol has changed since I posted this script 7 years ago. Try taking a look at https://wiki.vg/Authentication and the other pages on that wiki

@shai
Copy link

shai commented May 18, 2020

@jenrik yea I thought so, and thought you might want to update the code :)

@jenrik
Copy link
Author

jenrik commented May 19, 2020

I abandoned this scripts years ago, and I have no intention of updating it. If anybody needs a script to login to Minecraft you should read https://wiki.vg/Authentication and do your own implementation instead of trying to fix this crappy script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment