类型错误:字节索引必须是整数或切片,而不是 str

新手上路,请多包涵
request = requests.get("http://api.roblox.com/Marketplace/ProductInfo?assetId=1834225941").content
print(str(request["Sales"]))

这给出了以下错误:

 Traceback (most recent call last):
  File "C:\Users\yorks\Desktop\BloxUtility\bot.py", line 22, in <module>
    print(int(request["Sales"]))
TypeError: byte indices must be integers or slices, not str

你能帮我吗?

原文由 IIWasted1k 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 922
1 个回答

这应该工作

import requests
import json
request = requests.get("http://api.roblox.com/Marketplace/ProductInfo?assetId=1834225941").text
a = json.loads(request)
print(a['Sales'])

您可以在 此处 阅读反序列化

原文由 Tristo 发布,翻译遵循 CC BY-SA 4.0 许可协议

推荐问题