开发者

how to download in python

开发者 https://www.devze.com 2023-01-28 02:11 出处:网络
I am writing a script which will run on my server. Its pu开发者_开发百科rpose is to download the document. If any person hit the particular url he/she should be able to download the document. I am usi

I am writing a script which will run on my server. Its pu开发者_开发百科rpose 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?


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.


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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消