我正在尝试制作一个Minecraft名称狙击手,以便在该名称可用时立即更改帐户名称。您基本上输入了信息,然后在名称可用之前几秒钟运行它。然后,它应该发送多个请求以将用户名更改为“目标”用户名。但是,请求带有错误400。
import requests
username = input("username: ")
password = input("password: ")
bearer_key = input("Bearer Key: ")
target = input("Target Username: ")
useragent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4145.106 Safari/537.36'
us = req=requests.get(f'https://api.mojang.com/user/profile/agent/minecraft/name/{username}').json()
profileid = us['id']
print(profileid)
auth = 'Bearer ' + bearer_key
snipe = 0
while snipe < 100:
s = requests.post(f'https://api.mojang.com/user/profile/{profileid}/name', headers={'Authorization': auth,'User-Agent': useragent}, json={"name": username,"password": password})
print(s.status_code)
if s.status_code == 204:
print(f'{username} is now yours!')
snipe = snipe + 100
else:
snipe = snipe + 1
print(f"{snipe} retrying")
这是我用来更改名称并收到400错误的代码。我知道该错误与requests.post行有关,但我无法弄清楚出了什么问题。
编辑:
import requests
username = input("username: ")
password = input("password: ")
uuid = input("UUID: ")
bearer = input("Bearer Key: ")
wanted_name = input("Target Username: ")
snipe = 0
while snipe < 100:
url = 'http://api.mojang.com/user/profile/' + uuid + '/name'
req = requests.post(url, headers={'Authorization' : bearer,}, json={"name": wanted_name, "password": password})
print(req.status_code)
if req.status_code == 204:
print(f'{username} is now yours!')
snipe = snipe + 100
else:
snipe = snipe + 1
print(f"{snipe} retrying")
```
欢迎来到SO!
我认为您没有使用适当的发布方法。这是您应该使用的:
url = 'http://api.mojang.com/user/profile/' + uuid + '/name'
req = requests.post(url, headers={'Authorization': bearer}, json={"name": wanted_name,"password": password})
这是您可以用来了解如何向Mojang发出请求的链接。
这是另一个链接,将有助于理解不同的HTTP状态代码及其含义。
我的另一个小修改是让用户输入UUID,而不是发出get请求。就我个人而言,这对我来说很有意义,因为UUID是恒定的,并且永远不会像承载者那样变化(我敢肯定,您知道您可以在NameMC上找到它)。
另外,我认为您应该研究使此狙击手更好的一些东西:线程,异步和json包。这些也可能会改善您的机器人性能。
让我知道这个是否奏效。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句