How to download the application?

I am using urllib2 to (try) downloading a file from a website. A file can only be loaded after specifying some form fields. I can create a request and get a response without any problems, for example:

req = urllib2.Request(url, data, headers) response = urllib2.urlopen(req) 

When I look at response headers like this print response.info()['Content-Disposition'] , I see the file there, i.e. it prints something like attachment;filename=myfile.txt

But how can I download the application? If I do response.read() , I just get a string containing the HTML page of the page at the URL. The fact is that the URL is not a file, it is a โ€œattachmentโ€ web page, and I am trying to download this application from urllib2. I believe that the attachment is dynamically generated, so it is not just sitting on the server.

+4
source share
1 answer

The problem was that I did not send all the necessary headers. In particular, it is important that I send the correct cookies to the request headers. I have done the following:

  • Open Chromium (or Chrome) and press Ctrl + Shift + I to open the developer tools.
  • Click "Network"
  • Go to the page where the file should be uploaded.
  • Click the newly created entry in the developer tools and click "Titles." This is where I got all the heading information I needed to send.
+2
source

All Articles