大家好,所以我只是在玩API试图创建一些东西,可以从roblox目录购买一个项目,但我遇到了一个奇怪的错误,并希望您的支持
import re
import json
from requests import post, get
cookie = "somethingicantshow"
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("https://www.roblox.com/library/" + str(ID))
text = detail_res.text
info = post("https://catalog.roblox.com/v1/catalog/items/details",
json={"items": [{"itemType": "Asset", "id": int(ID)}]},
headers={"x-csrf-token": token}, cookies={".ROBLOSECURITY": cookie}).json()["data"][0]
productId = post("https://apis.roblox.com/marketplace-items/v1/items/details",
json={"itemIds": [info.get("collectibleItemId")]},
headers={"x-csrf-token": token}, cookies={".ROBLOSECURITY": cookie}) #int(get("https://api.roblox.com/marketplace/productinfo?assetId="+ str(ID)).json("ProductId"))#["ProductId"])
productId = productId.json()[0]["collectibleProductId"]
expectedPrice = 0 #int(re.search("data-expected-price=\"(\d+)\"", text).group(1))
expectedSellerId = 1 #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
}
dataLoad = json.dumps(data)
buyres = post("https://economy.roblox.com/v1/purchases/products/" + str(productId), headers=headers,
data=dataLoad,
cookies={".ROBLOSECURITY": cookie})
if buyres.status_code == 200:
print("Successfully bought item")
else:
print("failed" + str(buyres.status_code))
错误是:
Traceback (most recent call last):
File "C:\Users\Aarush Kumar\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Aarush Kumar\AppData\Local\Programs\Python\Python311\Lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Aarush Kumar\AppData\Local\Programs\Python\Python311\Lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Aarush Kumar\AppData\Local\Programs\Python\Python311\Lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Aarush Kumar\Downloads\limitedsnipe\limitedSniper.py", line 24, in <module>
productId = productId.json()[0]["collectibleProductId"]
^^^^^^^^^^^^^^^^
File "C:\Users\Aarush Kumar\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
会很感激你的帮助的。谢谢。
我尝试了很多东西,并在devforum上阅读了很多主题,但由于这是一个python错误,我不得不从这里寻求帮助。
1条答案
按热度按时间yeotifhr1#
JSON是一种人类可读的数据格式。它基本上将字典编码为一个长字符串,用于存储。它还允许将字符串解码为内存中的字典对象。
你得到了一个
JSONDecodeError
,所以我猜你从roblox API得到的json字符串不是有效的json。你可以通过打印出roblox API中的数据,看看它是否像json数据来进行调查,还有在线的json验证器。