You need to check to see if an enemy or item exists before trying to find its properties. To do this, you need to add if enemy and if item to the beginning of your if-statements to check if the item or enemy exists.
I figured part of it out, but my hero still dies by lightning
while True:
enemy = hero.findNearestEnemy()
if enemy:
if enemy.type != "burl" or "thrower" < 15:
hero.attack(enemy)
item = hero.findNearestItem()
if item:
if item.type != "gem" or "mushroom" < 15:
hero.moveXY(item.pos.x, item.pos.y)