urllib.request.urlretrieve not downloading files over HTTPS
<p>The below URL is the download link to download a text file.
If I paste the URL in the Firefox it downloads the actual contents i.e text file. But, when used <code>urlretrieve</code> it is giving me some html source code file.</p>

<pre><code>&gt;&gt;&gt; import urllib
&gt;&gt;&gt; down_link='URL' #URL is a ***HTTPS*** link to download .txt file
&gt;&gt;&gt; file=urllib.request.urlretrieve(down_link)
</code></pre>

<p>this is the output I get:</p>

<pre><code>&gt;&gt;&gt;
('C:\\Users\\rakesh.j.kulkarni\\AppData\\Local\\Temp\\tmps7559wgi'
http.client.HTTPMessage object at 0x03A3C610&gt;)
</code></pre>

<p>when opened the file I get html source file which when opened with browser it the same webpage's login form,</p>

<p>So i have to come up with the alternate process to do the same for time being until the problem gets resolved</p>

<pre><code>subprocess.Popen(["C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", down_link])
</code></pre>

<p>I then go to downloads and work on the file.</p>

<p>First of, you should import <code>urllib.request</code>, and not just urllib (in Py3).<br> And you are assigning the object to a variable so its giving you the object instance as output.
Nothing wrong with that, just to give you a quick fix, try doing:</p>

<pre><code>In [1]: import urllib.request

In [2]: down_link = "http://vignette3.wikia.nocookie.net/shipoffools/images/4/42/Surprised_Luffy.jpg/revision/latest?cb=20120921134043"

In [3]: path_to_save = "../luffy.jpg"

In [4]: urllib.request.urlretrieve(down_link, path_to_save)
Out[4]: ('../luffy.jpg', &lt;http.client.HTTPMessage at 0x47f6af0&gt;)
</code></pre>

<p>This will work just fine, saving the image where you want.
If you dont specify the path_to_save, then thats fine too, as it will download anyways and the path will be the <code>tmp</code> directory, In your case it would be <code>C:\\Users\\rakesh.j.kulkarni\\AppData\\Local\\Temp\\</code> folder.</p>

<p>In the case of <code>https</code> related error or any other problem, there is a cleaner way of doing it, by reading the file with <code>urlopen</code> and saving it in a file on your computer:</p>

<pre><code>In [5]: import urllib.request as req

In [6]: down_link = "https://vignette3.wikia.nocookie.net/shipoffools/images/4/42/
   ...: Surprised_Luffy.jpg/revision/latest?cb=20120921134043"

In [7]: fname = "../luffy.jpg"

In [8]: with req.urlopen(down_link) as d, open(fname, "wb") as opfile:
   ...:     data = d.read()
   ...:     opfile.write(data)
   ...:
</code></pre>

<p><strong>NOTE</strong>: This method can take some time, but works just fine for normal small files.</p>

python python-3.x urllib