0

I am trying to create a Python / flask webapp which takes a query equal to a dropbox directory, then opens windows explorer to that location. It works on a local machine but I need it to work on my Heroku server.

I have tried using %HOMEPATH% / "Dropbox Directory" which works when I copy and paste into the directory.

@app.route("/", methods=["GET","POST"])
def redirect_URL():
    url = request.args.get('url')
    HP = str(Path.home())
    path = Path(HP + url)

    string = r'explorer "{}"'.format(path)
    print(string)
    subprocess.Popen(string)
    return "success"

When something like domain.com/?url="dropbox directory" the app should open windows explorer to that location.

The above code runs fine on the local system. But Path.home returns the app folder

Aksen P
  • 4,564
  • 3
  • 14
  • 27
Croc
  • 789
  • 7
  • 13

2 Answers2

2

There's some good news and some bad news.

The good news is that there's a reason you're getting the wrong directory, which as you know is because Path.home() is returning your app's directory.

The bad news is that's never going to change. Your code is running on the server, so not only will Path.home() always return your app's directory, there's nothing you can do to get the directory you want.

Further more subprocess.Popen(string) will run the process on your server. This is why it works from localhost, but not on heroku. You cannot use a website to run a process on the client machine.

So, what you want to do is not possible from a website.

Matt Ellen
  • 11,268
  • 4
  • 68
  • 90
0

The Python code of your Flask application runs on heroku server. It has nothing to do with the desktop machine of your visitor. Actually, your visitor could load your app from his iPhone, Android phone or a macOS laptop.

So, to interact with the visitor machine, you have to look around HTML5, JavaScript and related technologies. These languages are interpreted and executed in the visitor's browser. But for security reasons, you will not be able to open a Windows Explorer instance on your users machine without using some high level (and probably unsecure) tools written in Java or ActiveX or something appproaching.

Antwane
  • 20,760
  • 7
  • 51
  • 84
  • Okay thanks for the comment. I see what you are saying so the code would have to execute from the frontend on client machine. After a look at a fair few other topics it seems due to security risks, what I am trying to do is not possible. – Croc Jul 17 '19 at 12:42