title: PyPDF2 Encrypting PDF with Python on Windows: AttributeError: 'tuple' object has no attribute 'write'
body: <p>Edit to include full Code:  Program basics -- Take CSV file of ID/EMAIL/PASSWORD, and create dictionary1.  Create a dictionary2 of ID/File in a path. </p>
  
  <p>Use Dictionary2 to lookup password in Dict1, apply encryption, and finally email using email in Dict1.  I'm stuck at the encryption part at this point.</p>
  
  <p>I've read some questions and google articles about needing to open the file, but I'm not sure how to open the "output" item...  </p>
  
  <p>Error: </p>
  
  <pre><code>Traceback (most recent call last):
    File "CommissionSecurity.py", line 54, in &lt;module&gt;
      output.write(outputStream)
    File "build\bdist.win-amd64\egg\PyPDF2\pdf.py", line 472, in write
  AttributeError: 'tuple' object has no attribute 'write'
  </code></pre>
  
  <p>Code: </p>
  
  <pre><code>import os 
  import re
  import csv
  import PyPDF2
  
  
  # Create a dictionary with the csv values
  EmailDict = dict()
  with open('commissionrepemaillist.csv', 'r') as infile:
      reader = csv.reader(infile)
      for row in reader :
          REP = row[0]
          EMAIL = row[1]
          PASSWORD = row[2]
          EmailDict[REP] = EMAIL, PASSWORD
  
  # create dictionary of IDs and Pdf Files
  FileDict = dict()
  path = "C:\\Apps\\CorVu\\DATA\\Reports\\AlliD\\Monthly Commission  Reports\\Output\\pdcom1"  
  for FILE in os.listdir(path):
      split = re.split("[_.]", FILE)
      ID = split[1]
      FileDict[ID] = FILE
  
  for ID in FileDict:
      # print REP
      # print ID # debug: REP always coming over 764 
      if ID in EmailDict : 
          #print FileDict[ID]
          path = "C:\\Apps\\CorVu\\DATA\\Reports\\AlliD\\Monthly Commission Reports\\Output\\pdcom1\\"
          file = open(os.path.join(path + FileDict[ID]), 'rb')
          output = PyPDF2.PdfFileWriter()
          input = PyPDF2.PdfFileReader(file)
  
          print ID, EmailDict[ID][1]  # returning the correct value for encryption
          output.encrypt(EmailDict[ID][1])
          outputStream = (file, "wb")
          output.write(outputStream)
  
          output.close()
          input.close()
  
      else : continue
  </code></pre>