Hacking the Fender, Step #15

Can’t get the JSON file in my directory and keep getting errors at step 15. Can someone help? Thanks in advance.

import csv

import json

compromised_users=[]

with open('passwords.csv') as password_file:  

  password_csv=csv.DictReader(password_file)

  for password_row in password_csv:

    compromised_users.append(password_row['Username'])

with open('compromised_users.txt', 'w') as compromised_user_file:

  for compromised_user in compromised_users:

    compromised_user_file.write(compromised_user)

with open('boss_message.json', 'w') as boss_message:

  boss_message_dict={

    'recipient': 'The Boss',

    'message': 'Mission Success'

  }

json.dump(boss_message_dict, boss_message)

Please post the error(s) you are seeing, and the basic format of the input CSV file.

1 Like

Here’s the error:

Traceback (most recent call last):
File “script.py”, line 31, in
json.dump(boss_message_dict, boss_message)
File “/usr/lib/python3.6/json/init.py”, line 180, in dump
fp.write(chunk)
ValueError: I/O operation on closed file.

I don’t know where I can find the other information.