0

I am exporting a CSV file using python. What python by default does is it downloads the file automatically to the path given (Desktop if no path initialized). But what I want is it uses the browser through which I am working and requesting to download file,ie, it prompts me there to download the file (browser's dialog) and then I can download

Nikhil
  • 16
  • 7

1 Answers1

0

If you use tkinter, then this answer should provide the answer your looking for (tkFileDialog.askdirectory).

from tkinter import *
window=Tk()
window.directory=filedialog.askdirectory(initialdir="/", title="Select a directory to download {}".format(YourFileName))
print(window.directory)

This will prompt you for a location to download the file you would like just like you would see in a web browser. However, you may need to change the initialdir directory depending on what platform you are using (Windows, Linux, Mac). We would also need to see your current Python code you are running in order to see how it is downloading the file you are requesting.

BobserLuck
  • 154
  • 10
  • I want that to be downloaded via browser. That's why I'm trying with request and response headers but that isn't working – Nikhil Oct 24 '18 at 07:05
  • @Nikhil Ah, could be wrong but for that I believe you are at the mercy of the individual browser. To be able to automatically open and start giving the browser any commands, you would need to use that particular browser's API if there is any. A "browser" is a stand alone application. I know you can manipulate Internet Exploder, er uh... Internet Explorer with VB script and other languages supported by Microsoft due to there integration support. For things like Firefox and Google, that may not be possible. You could use tkinter to have a similar directory selector appear. – BobserLuck Oct 24 '18 at 07:17
  • actually i am writing script in erpnext (JavaScript) and in that i have created a custom button and on click of that button, the python requests are active and it is downloading the file. So what I want is on click of that button , python doesn't make it download automatically but send the request to client side so that it gets downloaded via browser – Nikhil Oct 24 '18 at 07:40
  • @Nikhil Ah, that seems to be more of an issue with erpnext and the system behind it. This question may be out of the scope of stackoverflow as this community mostly deals with more direct programming frameworks and languages rather than full stack development suites. None the less, to answer a question like this, we would need more information. What the specific javascript and python code is. Most likely additional code would need to be added to the javacscipt or python script. Your best bet would probably be to ask the erpnext community or development team as this might be common issue – BobserLuck Oct 24 '18 at 08:13