encoding url to short unique file name
<p>I want to save html to a file based on the url.</p>

<p>to get unique name to url I am using uuid.</p>

<pre><code>&gt;&gt;&gt; url = "https://www.google.co.in/?gfe_rd=cr&amp;ei=-koUWPf4HqzT8ge2g6HoBg&amp;gws_rd=ssl"
&gt;&gt;&gt; uuidstring = str(uuid.uuid5(uuid.NAMESPACE_DNS, url))
</code></pre>

<p>but i want to further shorten the name. Is there any way to shorten string to unique small string.</p>

<p>I tried base64 but I could not figure out.</p>

<pre><code>&gt;&gt;&gt; uuid.UUID(uuidstring).bytes.encode('base64').rstrip('=\n').replace('/', '_')
&gt;&gt;&gt; AttributeError: 'bytes' object has no attribute 'encode'
</code></pre>

<p>linked question: <a href="https://stackoverflow.com/questions/12270852/convert-uuid-32-character-hex-string-into-a-youtube-style-short-id-and-back">Convert UUID 32-character hex string into a &quot;YouTube-style&quot; short id and back</a></p>