TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'
chppppp opened this issue · 3 comments
This error seems to happen randomly
My code:
from draft_kings.data import Sport
from draft_kings.client import contests
a = contests(sport=Sport.NBA)
for i in a['groups']:
if i['games_count'] == 10:
print(i)
from draft_kings.client import available_players
#b = available_players(draft_group_id=33019)
b = available_players(draft_group_id=33024)
#b = available_players(draft_group_id=32732)
print(b)
Traceback (most recent call last):
File "dotool.py", line 13, in
b = available_players(draft_group_id=33024)
File "/home/lou/dotesting/test2/backend/venv36/lib/python3.6/site-packages/draft_kings/client.py", line 23, in available_players
return translate_players(response=response.json())
File "/home/lou/dotesting/test2/backend/venv36/lib/python3.6/site-packages/draft_kings/response_translators.py", line 58, in translate_players
"players": [translate_player(response=player) for player in response.get("playerList", [])],
File "/home/lou/dotesting/test2/backend/venv36/lib/python3.6/site-packages/draft_kings/response_translators.py", line 58, in
"players": [translate_player(response=player) for player in response.get("playerList", [])],
File "/home/lou/dotesting/test2/backend/venv36/lib/python3.6/site-packages/draft_kings/response_translators.py", line 33, in translate_player
"starts_at": dig(response, "dgst", transformer=from_unix_milliseconds_to_datetime),
File "/home/lou/dotesting/test2/backend/venv36/lib/python3.6/site-packages/draft_kings/utilities.py", line 23, in dig
return transformer(nested_data)
File "/home/lou/dotesting/test2/backend/venv36/lib/python3.6/site-packages/draft_kings/utilities.py", line 10, in from_unix_milliseconds_to_datetime
return datetime.fromtimestamp(unix_milliseconds / 1e3, tz=pytz.UTC)
TypeError: unsupported operand type(s) for /: 'NoneType' and 'float'
I am seeing the same thing when using available_players, but draftables is working for me
I think the players that are no longer available due to game start datetimes that already past are NoneType and it's trying to divide NoneType by float. I think this might fix it in utilities.py:
def from_unix_milliseconds_to_datetime(unix_milliseconds):
if unix_milliseconds is None:
unix_milliseconds = 0
return datetime.fromtimestamp(unix_milliseconds / 1e3, tz=pytz.UTC)
@ton86 good call out - lemme take a look at this.
I'm going to be revamping the project soon (just haven't had a ton of time to dedicate recently).