-1

New tab with provided url is not opening in Ubuntu 14.04 Same code works in Mac OS X Yosemite

I have flask installed on both Ubuntu 14.04 and Mac Yosemite Both have python 2.7.6 installed

Below is the source code:

import webbrowser
from flask import Flask
from flask import render_template

app = Flask(__name__)

@app.route('/', methods=['POST'])
def submit():
    url = 'https://www.google.com'
    webbrowser.open(url, new=0, autoraise=True)
    return render_template("index.html")

if __name__ == '__main__':
    app.debug = True
    app.run()

I am accessing the flask app on Mac on port 5000 whereas on Ubuntu I am accessing it on port 8080

Let me know what more information I need to provide to help me debug.


After Debugging I think whether this behavior is because of SSL certificate issue? In order to debug, I tried to create the environment on server same as my local machine where it is working. BI stopped the apache web server on my server and launched the flask app manually (so that I can access the page on port 5000) and tried to launch the page using http://127.0.0.1:5000 I observed that the python logs in the terminal were erased and the screen showed "≪ ↑ ↓ Viewing[SSL] <Google Maps>" in the bottom

Rookie
  • 735
  • 5
  • 11
  • 30
  • What exactly are you trying to do? Do you want someone to open the web browser (by default Safari) on your desktop when someone visits that page? – metatoaster Aug 28 '15 at 05:52
  • Yes @metatoaster. I have a button in my default html page. On clicking it I want to open a new tab with given url. It can be on any browser, not specifically safari. – Rookie Aug 28 '15 at 06:05
  • Let me rephrase. [`webbrowser.open`](https://docs.python.org/2/library/webbrowser.html) opens a browser on the **webserver** on this case (as that is what flask is in this case), is this exactly what you want? – metatoaster Aug 28 '15 at 06:10
  • yes. On [webbrowser.open](https://docs.python.org/2/library/webbrowser.html) should open url using default browser. As I have provided new=0, hence it should open in current browser. It works in Mac, but same thing doesn't work in Ubuntu. When I run it in my Mac, I use same machine's safari, but for server, I access the server page using ip address on same safari browser – Rookie Aug 28 '15 at 06:15

1 Answers1

4

Your current code does open new browser window, but on the machine where your server is running. If you want to open new tab in client's browser you can use HTML attribute target="_blank" like this:

<a href="http://www.google.com/" target="_blank">Button</a>
vitaliy
  • 444
  • 2
  • 9