Hi,
I am new to Python and trying to help a friend.
I need to use a try exception to fix the error here below.
Task exception was never retrieved
future: <Task finished coro=<notification_loop() done, defined at chesterfieldbot.py:167> exception=KeyError('iv_atk',)>
Traceback (most recent call last):
File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
result = coro.send(None)
File "chesterfieldbot.py", line 201, in notification_loop
hundredsarray = getNewHundreds(pokearray)
File "chesterfieldbot.py", line 139, in getNewHundreds
if (getIVPercent(newArray[i]) != 100.0):
File "chesterfieldbot.py", line 20, in getIVPercent
if (poke['iv_atk'] is None or poke['iv_def'] is None or poke['iv_sta'] is None):
KeyError: 'iv_atk'
I have listed the code sections below by the lines in which are mentioned in the above error. Any help will be appreciated as I'm not too sure how I should be implementing this. Please let me know if more details are needed as I am new here and a noob.
I just need to try and add a try exception or some exception to these to keep them running and alive rather than throwing an error.
Line 167
Posted above in more detail :)
I am new to Python and trying to help a friend.
I need to use a try exception to fix the error here below.
Task exception was never retrieved
future: <Task finished coro=<notification_loop() done, defined at chesterfieldbot.py:167> exception=KeyError('iv_atk',)>
Traceback (most recent call last):
File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
result = coro.send(None)
File "chesterfieldbot.py", line 201, in notification_loop
hundredsarray = getNewHundreds(pokearray)
File "chesterfieldbot.py", line 139, in getNewHundreds
if (getIVPercent(newArray[i]) != 100.0):
File "chesterfieldbot.py", line 20, in getIVPercent
if (poke['iv_atk'] is None or poke['iv_def'] is None or poke['iv_sta'] is None):
KeyError: 'iv_atk'
I have listed the code sections below by the lines in which are mentioned in the above error. Any help will be appreciated as I'm not too sure how I should be implementing this. Please let me know if more details are needed as I am new here and a noob.
I just need to try and add a try exception or some exception to these to keep them running and alive rather than throwing an error.
Line 167
#This runs the loop to post notifications about rare pokemon. async def notification_loop(): while not bot.is_closed(): await bot.wait_until_ready() global desiredPokemon, savedRares, savedHundreds payload = { 'api-key': '*API KEY HERE*', 'area': 'chesterfield', 'type': 'pokemon', 'fields': 'id,pokemon_id,lat,lon,iv_atk,iv_def,iv_sta', }Line 201
if (len(pokearray) == 0 or seriousError): raresarray = [] hundredsarray = [] else: raresarray = getNewRares(pokearray) hundredsarray = getNewHundreds(pokearray)Line 139
or i in range(0, len(newArray)): if (getIVPercent(newArray[i]) != 100.0): indexToRemove = indexToRemove + [i] indexToRemove = sorted(indexToRemove, reverse=True) for index in indexToRemove: newArray.pop(index)Line 20
def getIVPercent(poke): if (poke['iv_atk'] is None or poke['iv_def'] is None or poke['iv_sta'] is None): return 0 else: return ((float(poke['iv_atk'])+float(poke['iv_def'])+float(poke['iv_sta']))/45.0)*100.0
Posted above in more detail :)