Forums

how to access localhost:8000

Hi I am a newbie to your site, I have a bokeh server which show the output at localhost:5006, can you please let me know can i access that page?

Unfortunately you won't be able to access your local computer from code running on PythonAnywhere. When you run code on our site, it runs on our servers, and they are no more able to access your local network than any other computer out there on the Internet.

The bokeh server is running in bash console of my account in pythonanywhere.com. So ideally the localhost is actually running in ur server, and my website is also running in ur server, i just want to connect the website with the bokeh server to show my plots.

Like in any other vm, i would run my website and my bokeh server at localhost, and then anyone can see my website and the bokeh plot by going to browser and entering the public IP of that vm, Internally the website captures the bokeh plot running in the local host and displays it to the browser.

I need to achieve the same in pythonanywhere.com

The server you run in the console is not accessible to the outside world.

To make your bokeh server available you need to deploy it as a webapp on "Web" page on PythoanAnywhere. Here is an example of deployment of bokeh embedded in Flask https://github.com/bokeh/bokeh/blob/1.3.4/examples/howto/server_embed/flask_embed.py You need your webapp to by wsgi compatibile. Bokeh server itself is not.

Thank you for your reply.

I have done the same setup in GOOGLE CLOUD VM, and the localhost:5006 can be accessible to outside world by just replacing the localhost with the publicIP of that VM, and the server runs internally on its Private IP.

The same if I need to do in PythonAnywhere.com, can you please help in knowing the process to get the Public IP and Private IP?

Is bokeh server a Python WSGI application? if so, then you can go to your web tab, add a new web app, use "manual configuration" when asked to choose framework, edit the wsgi script in /var/www, then reload web app. If bokeh server is not a Python WSGI app, then you won't be able to deploy it on PythonAnywhere

+1 to what @dull says. PythonAnywhere works very differently to Google Cloud VMs, and you need to set up websites on the "Web" tab. You'll need to embed your Bokeh app inside a Flask app using the technique that @fjl linked to above, and that will make it a WSGI application which you'll be able to call from there.

I've tried copying the exact code from the link posted by @jfl. I created a folder "/home/bhek/bokehflask" where I put the "flask_embed.py" file from the link, and created a subfolder "/home/bhek/bokehflask/templates" where I put the "embed.html" file from the link. I did not modify these two files in any way.

Then I created a standard flask web app, and changed the WSGI configuration file in two places: changing "/mysite" to "/bokehflask" at line 11 and changing "flask_app" to "flask_embed" at line 16. I also changed the Source Code field from "/home/bhek/mysite" to "/home/bhek/bokehflask".

This results in displaying the contents of the "embed.html" file, but the bokeh content is nowhere to be seen.

Edit2: I replicated all of this on my local machine, and turns out that opening "http://127.0.0.1:8000/" in a web browser yields the same result: only the contents of the html file. However, after looking at the errors, it turns out that opening "http://localhost:8000/" does show the bokeh plot (along with the html content). How can I achieve this in the web app?

Edit3: I just figured out there is a small mistake in the description on github. The guide tells you to open "http://127.0.0.1:8000/", while it is actually "localhost:8000" that is allowed at line 48 of "flask_embed.py". Changing the file to allow "127.0.0.1:8000" now shows the bokeh plot, while "localhost:8000" does not anymore. This leads me to the question which port exactly to allow on the web app, as both of these options (in the "flask_embed.py" file) do not result in the bokeh content being displayed.

Edit: apologies, the following text from my original question is now irrelevant. I made a small mistake correctly copying the contents of the "flask_embed.py" file (the last line was not indented correctly).

I get the following error:

ERROR:root:OSError: [Errno 98] Address already in use

ERROR:root: File "/var/www/bhek_pythonanywhere_com_wsgi.py", line 16, in <module>

ERROR:root: from flask_embed import app as application # noqa

ERROR:root: File "/home/bhek/bokehflask/flask_embed.py", line 60, in <module>

ERROR:root: app.run(port=8000)

The "flask_embed.py" file references ports in several places: port 5006 at line 41, and port 8000 at lines 48, 56, and 60. Where does it go awry? I've tried opening "http://127.0.0.1:8000/" in my browser and it shows nothing.

Remove the app.run(port=8000) line. PythonAnywhere handles this automatically.

Also, you don't need to run the app from a console. Just set it up as a Flask app on the "Web" page, and then the website will become available at http://bhek.pythonanywhere.com/

Thanks for the quick replies.

@dull I've tried this at your suggestion, without results. It still only displays the html content.

@giles Yes, I am not using consoles at all. I only visit the personal webpage.

I've also tried changing "localhost:8000" to "bhek.pythonanywhere.com:8000" at line 48, with identical results (i.e. only html content).

I can't, for the life of me, get this example to work. I highly suspect it has to do with the allow_websocket_origin at line 48 of "flask_embed.py", as that was the one thing I needed to change in order to get this example working on my local machine. Any help is much appreciated.

You aren't supposed to have to manage networking things like IP addresses or ports. The only thing you need to make the WSGI server run the site is a callable named application in your WSGI script. Make sure you are reloading your web app

Web apps are not served on arbitrary ports, only on port 80 and 443 (the standard ones for http and https). So you need to use one of those to access your web app.