roblox从目录中购买一个项目

50few1ms  于 2021-09-08  发布在  Java
关注(0)|答案(2)|浏览(576)

我写了一个脚本,应该从目录中购买资产。

import re
from requests import post, get

cookie = "blablabla"
ID = 1562150

# getting x-csrf-token

token = post("https://auth.roblox.com/v2/logout", cookies={".ROBLOSECURITY": cookie}).headers['X-CSRF-TOKEN']
print(token)

# getting item details

detail_res = get(f"https://www.roblox.com/library/{ID}")
text = detail_res.text

productId = int(get(f"https://api.roblox.com/marketplace/productinfo?assetId={ID}").json()["ProductId"])
expectedPrice = int(re.search("data-expected-price=\"(\d+)\"", text).group(1))
expectedSellerId = int(re.search("data-expected-seller-id=\"(\d+)\"", text).group(1))

headers = {
    "x-csrf-token": token,
    "content-type": "application/json; charset=UTF-8"
}

data = {
    "expectedCurrency": 1,
    "expectedPrice": expectedPrice,
    "expectedSellerId": expectedSellerId
}

buyres = post(f"https://economy.roblox.com/v1/purchases/products/{productId}", headers=headers,
              data=data,
              cookies={".ROBLOSECURITY": cookie})

if buyres.status_code == 200:
    print("Successfully bought item")

问题是它不知何故没有购买任何错误为500(internalservererror)的商品。有人告诉我,如果我将json.dumps()添加到脚本中,它可能会工作。如何在此处添加json.dumps()(虽然我阅读了文档,但我不理解),以及如何修复此问题,以便脚本购买项目?非常感谢任何能帮助我的人。

tzcvj98z

tzcvj98z1#

导入json包。
dumps()将python字典转换为json字符串。
我猜这就是你想要的。

buyres = 
post(f"https://economy.roblox.com/v1/purchases/products/{productId}", 
headers=json.dumps(headers),
          data=json.dumps(data),
          cookies={".ROBLOSECURITY": cookie})
e4eetjau

e4eetjau2#

我终于找到了答案,我不得不这样做:

dataLoad = json.dumps(data)
buyres = post(f"https://economy.roblox.com/v1/purchases/products/{productId}", headers=headers,
              data=dataLoad,
              cookies={".ROBLOSECURITY": cookie})

相关问题