title: File extension from MIME type with ;charset=UTF-8
body: <p>I have a Python web crawler which is downloading files with different extensions. To get the extension from the HTTP header content type, I am using the Python library <a href="https://docs.python.org/3/library/mimetypes.html#module-mimetypes1" rel="nofollow noreferrer">mimetypes</a>.</p>
  
  <pre><code>http_header = session.head(url, headers={'Accept-Encoding': 'identity'})
  extension = mimetypes.guess_extension(http_header.headers['content-type'])
  </code></pre>
  
  <p>Everything is working fine, except when the HTTP header content type contains<br>
  <code>;charset=UTF-8</code>. E.g. <code>mimetypes.guess_extension</code> is returning <code>None</code> for the following examples</p>
  
  <pre><code>content-type: text/plain;charset=UTF-8 # extension should be .txt OR  
  content-type: text/x-c;charset=UTF-8   # extension should be .java
  </code></pre>
  
  <p>Check with mimetypes:</p>
  
  <pre><code>&gt;&gt;&gt; import mimetypes
  &gt;&gt;&gt; print(mimetypes.guess_extension('text/plain;charset=UTF-8'))
  None
  &gt;&gt;&gt; 
  </code></pre>
  
  <p><strong>Question: How do I handle this and get the correct extension from content-types ending with <code>;charset=UTF-8</code>?</strong> </p>
  
  <p>I guess it is not a good solution to catch such exceptions with an if statement since I never know if the whitelist is complete or whether I am missing some content-type.</p>