# Bokeh server embedded in gunicorn/Flask hosted to cloud

**URL:** <https://discourse.bokeh.org/t/bokeh-server-embedded-in-gunicorn-flask-hosted-to-cloud/6199>\
**Category:** Community Support\
**Tags:** server\
**Created:** [August 22, 2020, 4:11pm UTC](https://discourse.bokeh.org/t/bokeh-server-embedded-in-gunicorn-flask-hosted-to-cloud/6199 "2020-08-22T16:11:13Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![\_jm](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/_/ac91a4/32.png) [@\_jm](https://discourse.bokeh.org/u/_jm)\
**Post date:** [August 28, 2020, 8:48pm UTC](https://discourse.bokeh.org/t/bokeh-server-embedded-in-gunicorn-flask-hosted-to-cloud/6199/11 "2020-08-28T20:48:03Z")

</div>

@p-himik @Bryan

I am trying a different architecture currently using separate Heroku dynos for the Flask app and the bokeh server.

In the following description of the problem currently faced, `<masked-app-name>` is a placeholder for my actual application’s name.

I can navigate to the server just fine via a web browser, e.g.

`https://<masked-app-name>.herokuapp.com/`

However, when I try to embed it from Flask via pull\_session() within a client context manager, it fails.

Here’s the Flask app code.

```
from flask import Flask, render_template

from bokeh.client import pull_session
from bokeh.embed import server_session

PANEL_URL = "https://<masked-app-name>.herokuapp.com"

app = Flask( __name__ )

@app.route('/', methods=['GET'])
def bkapp_page():
    with pull_session(url=PANEL_URL) as session:
        script = server_session(session_id=session.id, url=PANEL_URL)
        return render_template("embed.html", script=script, template="Flask")

```

The web browser for the Flask app shows `500 Server Internal Error`, which is also reflected in the JavaScript console.

And the Heroku log excerpt shows the following error stack trace from Bokeh client session logic …

```
2020-08-28T20:07:30.436217+00:00 app[web.1]: File "/app/main.py", line 12, in bkapp_page

2020-08-28T20:07:30.436217+00:00 app[web.1]: with pull_session(url=PANEL_URL) as session:

2020-08-28T20:07:30.436217+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/bokeh/client/session.py", line 120, in pull_session

2020-08-28T20:07:30.436218+00:00 app[web.1]: session.pull()

2020-08-28T20:07:30.436218+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/bokeh/client/session.py", line 381, in pull

2020-08-28T20:07:30.436218+00:00 app[web.1]: self.check_connection_errors()

2020-08-28T20:07:30.436220+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/bokeh/client/session.py", line 367, in check_connection_errors

2020-08-28T20:07:30.436220+00:00 app[web.1]: raise OSError(f"Check your application path! The given Path is not valid: {self.url}")

2020-08-28T20:07:30.436220+00:00 app[web.1]: OSError: Check your application path! The given Path is not valid: ws://<masked-app-name>.herokuapp.com/ws

```

Is there a way to work around the ws:// protocol substitution in the URL to make it behave as if a user is navigating directly to the server via https?

---

_[View the full topic](https://discourse.bokeh.org/t/bokeh-server-embedded-in-gunicorn-flask-hosted-to-cloud/6199)._
