So , i made this small program to update about the lowest_price of a specific item on steam market , it runs a loop and gets json response.
It works fine initially , displays the price , but after a while it shows the error.
The program code :
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 ())
Here is the output of the program :
$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]
This error occurs when you are trying to index an object that is of type None (i.e: the object has no value).
Here your None object is your json_data variable, which means that json.loads (response.text) returns None.
You can avoid this error by adding an if statement that will check if the value is not None:
if json_data is not None:
return json_data['lowest_price']
return None
Or with a try-except statement:
try:
return json_data['lowest_price']
except Exception as e:
return None # or you can raise an exception if you want
You're experiencing this problem since you're making too many requests to the server really fast.
To be specific, the server replies with http error code 429
Consider waiting for a few seconds before sending successive requests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With