小编KIN*_*ING的帖子

Python - “NoneType”对象不可订阅(Steam 物品价格的小程序)

因此,我编写了这个小程序来更新 Steam 市场上特定商品的最低价格,它运行一个循环并获取 json 响应。

最初它工作正常,显示价格,但一段时间后它显示错误。

程序代码:

import json
import requests

def GetPrice () :

    response = requests.get ('https://steamcommunity.com/market/priceoverview/?appid=264710&currency=1&market_hash_name=Planet%204546B%20Postcard')

    json_data = {}
    json_data = json.loads (response.text)

    return json_data ["lowest_price"]

while True :

    print (GetPrice ())
Run Code Online (Sandbox Code Playgroud)

这是程序的输出:

$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
$1.03
Traceback (most recent call last):
  File "C:\Users\Admin\Desktop\item_price.py", line 16, in <module>
    print (GetPrice ())
  File "C:\Users\Admin\Desktop\item_price.py", line 12, in GetPrice
    return json_data …
Run Code Online (Sandbox Code Playgroud)

python steam

3
推荐指数
1
解决办法
5244
查看次数

标签 统计

python ×1

steam ×1