2

so i have multiple 5 'Player' objects being created upon the start of my code, and about 24 different 'Skill' objects for each 'Player' Object, im using this to loop through my code

first_run = True

while True:
    for i in range(len(player_name)):
    if first_run is True:
        player[i] = Player(player_name[i], player_url[i], player_thumbnail[i])
        print(player[i].name, "'s Object Created")

    data = requests.get(player_url[i])
    statusCheck(data.status_code, player_name[i])
    data_processed = re.split(', |\n', data.text)

    storeData(data_processed, player[i], first_run)

logging.info("Sleeping for 10 Seconds")
time.sleep(10)
first_run = False

basically on the first run through of this while loop, it will create 5 player objects that have predefined names that are stored in a list above. now when my code reaches storeData(data_processed, player[i], first_run) it reaches an issue in that function, an issue saying that an attribute created when the first player object is created doesnt exist, it was working absolutely perfectly, and then suddenly it stopped working, i didnt even change anything and suddenly its no longer working, here is the function "storeData" ( further below is the log error )

def storeData(data_processed, player, first_run):
line_count = 0
for line in data_processed:
    if line != '':
        skill_data = line.split(',')
        if line_count < 24:
            player_skill = None
            player_skill = getattr(player, skills[line_count])
            player_skill.rank = skill_data[0]
            player_skill.level = skill_data[1]
            player_skill.xp = skill_data[2]
            line_count = line_count + 1
            if player_skill.last_level != player_skill.level and first_run is not True:
                logging.info(player.name, "Gained A Level in ", skills[line_count])
                pushLevelUp(discordUrl,skills[line_count-1], player, player_skill)
            player_skill.last_level = skill_data[1]

        elif line_count < 79:
            player_activity = getattr(player, activity[line_count - 24])
            player_activity.last_count = player_activity.count
            player_activity.rank = skill_data[0]
            player_activity.count = skill_data[1]
            line_count = line_count + 1

below is log error, i didnt change anything as i said, but it no longer finds player.skill.Overall ( using getattr )

    Traceback (most recent call last):
  File "*hidden*", line 42, in <module>
    storeData(data_processed, player[i], first_run)
  File "*hidden*", line 142, in storeData
    player_skill = getattr(player, skills[line_count])
AttributeError: 'NoneType' object has no attribute 'Overall'

Process finished with exit code 1

these are the lists in which i store the data for "skills"

skills = ['Overall', 'Attack', 'Defence', 'Strength', 'Hitpoints', 'Ranged', 'Prayer', 'Magic', 'Cooking',
      'Woodcutting', 'Fletching', 'Fishing', 'Firemaking', 'Crafting', 'Smithing', 'Mining', 'Herblore',
      'Agility', 'Thieving', 'Slayer', 'Farming', 'Runecrafting', 'Hunter', 'Construction']

here is a quick rundown

player_skill = getattr(player, skills[line_count]) on first iteration should point directly to the player object passed into the storeData function, for this example il use "player", as the object name... the getattr on first iteration should point directly to player.Overall, which would allow me to call player.Overall.level, however it says it cannot find player.Overall when using player_skill = getattr(player, skills[line_count])

here are my .py files https://pastebin.com/q2VEFGfk ( this is file called 'runebotClassData' ) and this https://pastebin.com/h7BEckgR is ( runebotTest.py )

as i said, i changed nothing, the api seems to be returning the data exactly as normal, and that error is occuring, please help

m e m e
  • 105
  • 2
  • 11
  • 1
    If `first_run` is `False` then `player[i]` remains `None` which is handed over as parameter `player` to `storeData` which then fails under some additional conditions. – Michael Butscher Jul 12 '20 at 21:30
  • oh sorry, i think i was testing at that point, the first definition of "first_run" should be true, but i set it to false whenever i want to test because it immediately prints embeded messages on discord if i do that – m e m e Jul 12 '20 at 21:45
  • sorry, i meant the declaration, the declaration of first_run was meant to = True, but even if it was set to True the problem still occurs – m e m e Jul 12 '20 at 22:52
  • You could check if "player" is None at beginning of "storeData" and raise a "ValueError" if so. This would at least show the error earlier and more reliably so that its cause can be found. – Michael Butscher Jul 13 '20 at 08:21
  • I will do some testing today, however if i recall it suddenly started working last night, and if so it might be an issue with the api , but im pretty sure the data was being sourced as normal – m e m e Jul 13 '20 at 10:17

1 Answers1

1

wow i overlooked that completely, i was blinded by the error pointing to where player[i] was being called, not where it was defined, and it wasnt defined if my testing mode was on ( first_run = False ) i should have paid more attention to the declaration

m e m e
  • 105
  • 2
  • 11