使用python request.post函数时请求错误400

诺亚

我正在尝试制作一个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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

请求使用POST进行工作,但使用PUT却收到400错误

Python Post调用抛出400错误请求

使用Request的request函数时,Github API响应为403

python请求POST 400错误

python post request抛出“ 400 Bad Request”

Python请求400错误

使用JSON正文发送POST请求时出现400响应

使用React时如何解决400错误请求错误?

使用数据表服务器端脚本Wordpress调用Ajax函数时遇到400错误请求

发生错误400(错误请求)时,使用Axios从POST捕获返回json

request(...)。那么在发出POST请求时不是函数错误

使用Python的request.post函数对动态HTML进行网页抓取时,如何指定“页码”?

使用request.post()在python中对XHR请求无响应

使用Python Socket GET请求获取400 Bad Request错误

Python请求POST-400-Python请求的错误请求

在Express.js上使用Axios向Spotify API发出POST请求时出现错误400

Python Django 1.7 def(request)函数-Post请求继续使用相同的函数

使用Pushbullet Ephemerals时出现400(错误请求)错误

从python向rails发布GET请求时,错误的Request-Line`m-urlencoded'错误

带有python 400错误请求的POST请求

在 Volley 中实现 POST 请求时出现错误代码 400,但在使用 OkHttp 时则不会

Python POST 请求 400 错误请求

400 Bad Request 使用 Axios 获取请求

使用 Google Api Batch Request 收到 400 Bad Request 错误

使用“_bulk”端点提交 POST 请求时,来自 elasticsearch 的 400

Scrapy FormRequest 在 Python 请求工作时返回 400 错误

请求的 URL 返回错误:400 Bad Request

使用 curl 到 Actix 服务器的 POST 请求失败并显示“400 Bad Request”

MERN:使用 POST 在等待获取时收到 400 错误错误请求