title: Download HTTP Content Disposition python
body: <p>Im stuck and in need of some help.  I cant to seem to find any reference on how to download the file.  Ive be using requests to find the file name but I dont know where to go from there.</p>
  
  <p>'Content-disposition': 'attachment;filename=MT0376_DealerPrice.zip'</p>
  
  <pre><code>Any help would be greatly appreciated 
  
  import requests
  import csv
  import urllib
  from urllib.request import urlretrieve
  import sys, os, base64, datetime, hashlib, hmac, urllib
  from time import gmtime, strftime
  import xml.etree.ElementTree as ET
  import math
  import time
  import zipfile
  
  
  dealerCode = 'Code'
  userName ='User'
  password = 'Pass'
  loginUrl = 'https://www.lemansnet.com/login'
  
  payload = {'rememberMe': 'on', 
             'dealerCode': dealerCode, 
             'dm': 4, 
             'userName': userName, 
             'password': password}
  
  
  r = requests.post(loginUrl, params=payload)
  
  
  token = r.headers['loginToken']
  
  
  with open ("parts.xml", "r") as myfile:
      requestBody = myfile.read().replace('\n', '')
  
  serviceURL = 'https://www.lemansnet.com/pricing/2013/pos'
  ContentType = 'Content-Type:text/xml'
  ContentLength = len(requestBody)
  loginToken = 'loginToken:' + token
  
  httparray = {'content': requestBody}
  
  xml = """&lt;pricing&gt;
  &lt;whoForDealer&gt;
  &lt;dealerCode&gt;MT0376&lt;/dealerCode&gt;
  &lt;/whoForDealer&gt;
  &lt;rememberPreferences&gt;1&lt;/rememberPreferences&gt;
  &lt;/pricing&gt;"""
  
  params = {'http': httparray}
  
  requestHeaders = {'Content-Type': 'text/xml',
                    'Content-Length': ContentLength, 
                    'charset': 'utf-8',
                    'loginToken': token,
                    'Cache-Control': 'no-cache',
                    'Pragma': 'no-cache',
                    'Connection': 'keep-alive'}
  files ={'file': ('parts.xml')}
  
  
  t = requests.post(serviceURL, data=xml, headers=requestHeaders)
  
  #print(r.url)
  #print(r.headers)
  #print(r.text)
  #print(r.status_code)
  #print(r.content)
  #print(t.url)
  #print(t.headers)
  #print(t.text)
  print(t.status_code)
  print(t.content)
  with open("MT0376_DealerPrice1.zip", "wb") as code:
      code.write(t.content)
  zip = t.headers['Content-disposition']
  #print(zip)
  
  #localName = zip.split('filename=')[1]
  #print(localName)
  
  
  
  print('end')
  </code></pre>
  
  <p>This is my current response from above code.</p>
  
  <pre><code>200
  b'PK\x03\x04\x14\x00\x08\x08\x08\x00H\x8aOF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1b\x00\x00\x00PriceFile_system_errors.txt\xe3\xf5M\xac\xc8\xcc-\xcdUHI\xcc\xcc\xa9T\xc8\xc9\xcc\xcd,QH\xadHNMMIM\xd1\xe3\xc5+\x0b\x00PK\x07\x08\xcdO\x92K#\x00\x00\x00&lt;\x00\x00\x00PK\x01\x02\x14\x00\x14\x00\x08\x08\x08\x00H\x8aOF\xcdO\x92K#\x00\x00\x00&lt;\x00\x00\x00\x1b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00PriceFile_system_errors.txtPK\x05\x06\x00\x00\x00\x00\x01\x00\x01\x00I\x00\x00\x00l\x00\x00\x00\x00\x00'
  end
  </code></pre>
  
  <p>Thanks for the help everyone,  I think I managed to figure this one out.  I edited the my code above to what I think is working correctly.  Unfortunately the website im gathering my info from only allows me to download the file 3 times a day so I wont be able to really test it until tomorrow.</p>