smmittal
smmittal

Reputation: 15

how to download in python

I am writing a script which will run on my server. Its purpose is to download the document. If any person hit the particular url he/she should be able to download the document. I am using urllib.urlretrieve but it download document on the server side not on the client. How to download in python at client side?

Upvotes: 0

Views: 375

Answers (4)

Overmind Jiang
Overmind Jiang

Reputation: 633

You might want to take a look at the SocketServer module.

Upvotes: 0

AndiDog
AndiDog

Reputation: 70218

If the script runs on your server, its purpose is to serve a document, not to download it (the latter would be the urllib solution).

Depending on your needs you can:

  • Set up static file serving with e.g. Apache
  • Make the script execute on a certain URL (e.g. with mod_wsgi), then the script should set the Content-Type (provides document type such as "text/plain") and Content-Disposition (provides download filename) headers and send the document data

As your question is not more specific, this answer can't be either.

Upvotes: 2

Philar
Philar

Reputation: 3897

If the document is on your server and your intention is that the user should be able to download this file, couldn't you just serve the url to that resource as a hyperlink in your HTML code. Sorry if I have been obtuse but this seems the most logical step given your explanation.

Upvotes: 1

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799310

Set the appropriate Content-type header, then send the file contents.

Upvotes: 1

Related Questions