【发布时间】:2020-06-21 16:08:53
【问题描述】:
所以,我做了这个小程序来更新 Steam 市场上特定商品的最低价格,它运行一个循环并获得 json 响应。
一开始可以正常工作,显示价格,但过了一会儿就显示错误。
程序代码:
import json
import requests
def GetPrice () :
response = requests.get ('https://steamcommunity.com/market/priceoverview/?appid=264710¤cy=1&market_hash_name=Planet%204546B%20Postcard')
json_data = {}
json_data = json.loads (response.text)
return json_data ["lowest_price"]
while True :
print (GetPrice ())
这是程序的输出:
$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 ["lowest_price"]
TypeError: 'NoneType' object is not subscriptable
[Finished in 20.2s]
【问题讨论】:
-
你有什么理由一遍又一遍地检查同一个网址吗?