Roblox 从目录中购买物品

时间:2021-07-09 15:00:08

标签: python python-3.x python-requests roblox

我编写了一个脚本,用于从目录中购买资产。

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()(虽然我阅读了文档,但我不明白)以及如何解决此问题以便脚本购买项目? 非常感谢任何可以帮助我的人。

2 个答案:

答案 0 :(得分:0)

导入json包。

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})

答案 1 :(得分:0)

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

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