Python 3: Hacking the Fender Error Help?

So, I’m working on the “Hacking the Fender” freeform project in the Files section of Python 3:

Here is my code:

import csv

compromised_users = []

with open("passwords.csv", "w") as password_file:
  password_csv = csv.DictReader(password_file)
  for password_row in password_csv:
    print(password_row)

Everything was fine until I added the for loop. Now I get the following error:

Traceback (most recent call last):
  File "script.py", line 7, in <module>
    for password_row in password_csv:
  File "/usr/lib/python3.5/csv.py", line 109, in __next__
    self.fieldnames
  File "/usr/lib/python3.5/csv.py", line 96, in fieldnames
    self._fieldnames = next(self.reader)
io.UnsupportedOperation: not readable

My code is the same as the walk-through – I checked because I can’t find an issue with the code myself. Does anyone else see where I’m going wrong?

Thanks in advance!
Jen

1 Like

Did you mean to write,

password_row['Username']

?

1 Like

No, but even if I change it, I still get the same error. I get the same error if I change it to

pass
1 Like

Since we’re only reading, I wrote the first with as default,

with open("passwords.csv") as password_file:
  password_csv = csv.DictReader(password_file)
  for password_row in password_csv:
    print(password_row['Username'])

This is given in the instructions.

1 Like

Thank you! I must have misread the instructions based on the overall project premise. I knew it was going to be something ridiculous.

2 Likes