title: Write Binary data with python to a zip file
body: <p>I am tying to write a binary data to a zip file.</p>
  
  <p>The below works but if I try to add a <code>.zip</code> as a file extension to "check" in the variable <code>x</code> nothing is written to the file.  I am stuck manually adding <code>.zip</code></p>
  
  <pre><code>urla = "some url"
  tok = "some token"
  pp = {"token": tok}
  t = requests.get(urla, params=pp)
  b = t.content
  x = r"C:\temp" + "\check"
  z = 'C:\temp\checks.zip'
  with open(x, "wb") as work:
       work.write(b)
  </code></pre>
  
  <p>In order to have the correct extension appended to the file I attempted to use the module <code>ZipFile</code></p>
  
  <pre><code>with ZipFile(x, "wb") as work:
      work.write(b)
  </code></pre>
  
  <p>but get a <code>RuntimeError</code>:</p>
  
  <pre><code>RuntimeError: ZipFile() requires mode "r", "w", or "a"
  </code></pre>
  
  <p>If I remove the <code>b</code> flag an empty zipfile is created and I get a <code>TypeError</code>:</p>
  
  <pre><code>TypeError: must be encoded string without NULL bytes, not str
  </code></pre>
  
  <p>I also tried but it creates a corrupted zipfile.</p>
  
  <pre><code>os.rename(x, z ) 
  </code></pre>
  
  <p>How do you write binary data to a zip file.</p>