title: Python - Download file over HTTP and detect filetype automatically
body: <p>I want download a file via HTTP, but all the examples online involve fetching the data and then putting it in a local file. The problem with this is that you need to explicitly set the filetype of the local file.</p>
  
  <p>I want to download a file but I won't know the filetype of what I'm downloading.</p>
  
  <p>This is what I currently have:</p>
  
  <pre><code>urllib.urlretrieve(fetch_url,output.csv)
  </code></pre>
  
  <p>But if I download, say a XML file it will be CSV. Is there anyway to get python to detect the file that I get sent from a URL like: <a href="http://asassaassa.com/assaas?abc=123" rel="nofollow">http://asassaassa.com/assaas?abc=123</a> </p>
  
  <p>Say the above URL gives me an XML I want python to detect that.</p>