Embed "Uncaught SyntaxError: Unexpected token <"

Currently I am using 0.12.3

Embedding without url parameters works fine.

app_path = '/emptydetails_graph'
script = autoload_server(model=None,app_path=app_path, url="http://127.0.0.1:5006/")

When I add a parameter:

company = “name”

app_path = ‘/emptydetails_graph?name=’ + “%” + company + “%”

script = autoload_server(model=None, app_path=app_path, url="http://127.0.0.1:5006/") 

i get an “Uncaught SyntaxError: Unexpected token <” error found in

Bokeh Application html { width: 100%; height: 100%; } body { width: 90%; height: 100%; margin: auto; }

``

these are both loaded within:

<div class="bk-root">
    {{ the_script|safe }}
</div>


without the embedding http://localhost:5006/emptydetails_graph?name=%sheehy%/autoload.js?bokeh-autoload-element=8a4a408c-f0ab-48f1-a482-d1a7c056e9c7 loads fine.







removing the ?name=%’ + company + ‘%’ the app works fine. Are url parameters not allowed in bokeh?

···

On Monday, January 16, 2017 at 4:42:04 PM UTC-6, Rob Pritchard wrote:

Currently I am using 0.12.3

Embedding without url parameters works fine.

app_path = '/emptydetails_graph'
script = autoload_server(model=None,app_path=app_path, url="[http://127.0.0.1:5006/](http://127.0.0.1:5006/)")

When I add a parameter:

company = “name”

app_path = ‘/emptydetails_graph?name=’ + “%” + company + “%”

script = autoload_server(model=None, app_path=app_path, url="[http://127.0.0.1:5006/](http://127.0.0.1:5006/)") 


i get an “Uncaught SyntaxError: Unexpected token <” error found in

Bokeh Application

html {

width: 100%;

height: 100%;

}

body {

width: 90%;

height: 100%;

margin: auto;

}

``

these are both loaded within:

<div class="bk-root">
    {{ the_script|safe }}
</div>




without the embedding [http://localhost:5006/emptydetails_graph?name=%sheehy%/autoload.js?bokeh-autoload-element=8a4a408c-f0ab-48f1-a482-d1a7c056e9c7](http://localhost:5006/emptydetails_graph?name=%sheehy%/autoload.js?bokeh-autoload-element=8a4a408c-f0ab-48f1-a482-d1a7c056e9c7) loads fine.














simple_bokeh.py

from bokeh.plotting import figure, output_file, show,curdoc
from bokeh.models.widgets import Select
from bokeh.layouts import row, column

output_file("test.html")
p = figure()
name = ""

print("simple bokeh")
print("WHY NO PRINT")
args = curdoc().session_context.request.arguments
print(args)
if args.get('name') == None:
 name = 'sheehy'
else:
 name = str(args.get('name')[0])
 name_split = name.split('%')
 name = name_split[1];

p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=2)

curdoc().add_root(column(p))

running on 0.12.3 with: bokeh serve simple_bokeh.py --allow-websocket-origin=127.0.0.1:8000 --host '*'

Django:

app_path = ‘/simple_bokeh?name=%’ + ‘apple’ + ‘%’

script = autoload_server(model=None,
app_path=app_path ,
url=“http://127.0.0.1:5006/”)


HTML:

Experiment with Bokeh
    <script src="https://cdn.pydata.org/bokeh/release/bokeh-0.12.3.min.js"></script>
    <link rel="stylesheet" href="https://cdn.pydata.org/bokeh/release/bokeh-0.12.3.min.css">
    <script src="https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.3.min.js"></script>

</head>

            <div class="bk-root">
                {{ the_script|safe }}
            </div>

</body>
```


the error i am geting is
http://127.0.0.1:5006/simple_bokeh?name=$apple$/autoload.js?bokeh-autoload-element=5545c000-9fa0-4dd1-b622-008f57be18c1 Uncaught SyntaxError: Unexpected token <

which is found in:
Bokeh Application
    <style>
      html {
        width: 100%;
        height: 100%;
      }
      body {
        width: 90%;
        height: 100%;
        margin: auto;
      }
    </style>
</head>
<body>
   
    <div class="bk-root">
        <div class="bk-plotdiv" id="9b1aff35-ae75-4b83-8c44-1be3e409d990"></div>
    </div>
   
    <script type="text/javascript">
        (function() {
      var fn = function() {
        Bokeh.safely(function() {
          var docs_json = {};
          var render_items = [{"elementid":"9b1aff35-ae75-4b83-8c44-1be3e409d990","sessionid":"bHneUPffPF1iCHvxh9RmN6tRB9Fi6PpsrRWXCbTv6Iab","use_for_title":true}];
         
          Bokeh.embed.embed_items(docs_json, render_items, "ws://127.0.0.1:5006/simple_bokeh/ws");
        });
      };
      if (document.readyState != "loading") fn();
      else document.addEventListener("DOMContentLoaded", fn);
    })();
   
    </script>
</body>



···

On Monday, January 16, 2017 at 4:42:04 PM UTC-6, Rob Pritchard wrote:

Currently I am using 0.12.3

Embedding without url parameters works fine.

app_path = '/emptydetails_graph'
script = autoload_server(model=None,app_path=app_path, url="[http://127.0.0.1:5006/](http://127.0.0.1:5006/)")

When I add a parameter:

company = “name”

app_path = ‘/emptydetails_graph?name=’ + “%” + company + “%”

script = autoload_server(model=None, app_path=app_path, url="[http://127.0.0.1:5006/](http://127.0.0.1:5006/)") 


i get an “Uncaught SyntaxError: Unexpected token <” error found in

Bokeh Application

html {

width: 100%;

height: 100%;

}

body {

width: 90%;

height: 100%;

margin: auto;

}

``

these are both loaded within:

<div class="bk-root">
    {{ the_script|safe }}
</div>




without the embedding [http://localhost:5006/emptydetails_graph?name=%sheehy%/autoload.js?bokeh-autoload-element=8a4a408c-f0ab-48f1-a482-d1a7c056e9c7](http://localhost:5006/emptydetails_graph?name=%sheehy%/autoload.js?bokeh-autoload-element=8a4a408c-f0ab-48f1-a482-d1a7c056e9c7) loads fine.














The above code didnt copy correctly:

Bokeh Application html { width: 100%; height: 100%; } body { width: 90%; height: 100%; margin: auto; }

``

···

On Tuesday, January 17, 2017 at 1:29:07 PM UTC-6, Rob Pritchard wrote:

simple_bokeh.py

from bokeh.plotting import figure, output_file, show,curdoc
from bokeh.models.widgets import Select
from bokeh.layouts import row, column

output_file("test.html")
p = figure()
name = ""

print("simple bokeh")
print("WHY NO PRINT")
args = curdoc().session_context.request.arguments
print(args)
if args.get('name') == None:
 name = 'sheehy'
else:
 name = str(args.get('name')[0])
 name_split = name.split('%')
 name = name_split[1];



p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=2)


curdoc().add_root(column(p))

running on 0.12.3 with: bokeh serve simple_bokeh.py --allow-websocket-origin=127.0.0.1:8000 --host ‘*’





Django:


app_path = '/simple_bokeh?name=%' + 'apple' + '%'
script = autoload_server(model=None,
                         app_path=app_path ,
                         url="[http://127.0.0.1:5006/](http://127.0.0.1:5006/)")





HTML:
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Experiment with Bokeh</title>

        <script src="[https://cdn.pydata.org/bokeh/release/bokeh-0.12.3.min.js](https://cdn.pydata.org/bokeh/release/bokeh-0.12.3.min.js)"></script>
        <link rel="stylesheet" href="[https://cdn.pydata.org/bokeh/release/bokeh-0.12.3.min.css](https://cdn.pydata.org/bokeh/release/bokeh-0.12.3.min.css)">
        <script src="[https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.3.min.js](https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.3.min.js)"></script>


    </head>

                <div class="bk-root">
                    {{ the_script|safe }}
                </div>

    </body>
</html>





the error i am geting is
http://[127.0.0.1:5006/simple_bokeh?name=$](http://127.0.0.1:5006/simple_bokeh?name=$)apple$/autoload.js?bokeh-autoload-element=5545c000-9fa0-4dd1-b622-008f57be18c1 Uncaught SyntaxError: Unexpected token <


which is found in:


<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Bokeh Application</title>
       
<link rel="stylesheet" href="[http://127.0.0.1:5006/static/css/bokeh.min.css?v=7246afcfffc127faef7c138bce4742e9](http://127.0.0.1:5006/static/css/bokeh.min.css?v=7246afcfffc127faef7c138bce4742e9)" type="text/css" />
<link rel="stylesheet" href="[http://127.0.0.1:5006/static/css/bokeh-widgets.min.css?v=d9cb9322d940f107727b091ff98d9c70](http://127.0.0.1:5006/static/css/bokeh-widgets.min.css?v=d9cb9322d940f107727b091ff98d9c70)" type="text/css" />
       
<script type="text/javascript" src="[http://127.0.0.1:5006/static/js/bokeh.min.js?v=9d3af13f493d36073a89714f6a5240c6](http://127.0.0.1:5006/static/js/bokeh.min.js?v=9d3af13f493d36073a89714f6a5240c6)"></script>
<script type="text/javascript" src="[http://127.0.0.1:5006/static/js/bokeh-widgets.min.js?v=1af1302b8bd7fcc88c7bcafb8771497b](http://127.0.0.1:5006/static/js/bokeh-widgets.min.js?v=1af1302b8bd7fcc88c7bcafb8771497b)"></script>
<script type="text/javascript">
    Bokeh.set_log_level("info");
</script>
        <style>
          html {
            width: 100%;
            height: 100%;
          }
          body {
            width: 90%;
            height: 100%;
            margin: auto;
          }
        </style>
    </head>
    <body>
       
        <div class="bk-root">
            <div class="bk-plotdiv" id="9b1aff35-ae75-4b83-8c44-1be3e409d990"></div>
        </div>
       
        <script type="text/javascript">
            (function() {
          var fn = function() {
            Bokeh.safely(function() {
              var docs_json = <span style="color: #660;"

The Bokeh server accepts URL parameters when connections are made, and they are available to app code. But the way autoload_server currently constructs URLs is not compatible with URL parameters. You can see this by inspecting the script tag that gets generated:

  In [5]: print(autoload_server(None, app_path="/foo?bar"))

  <script
      src="http://localhost:5006/foo?bar/autoload.js?bokeh-autoload-element=e56d7065-48cf-4ac5-a80a-17b4ac5cf3cf&quot;
      id="e56d7065-48cf-4ac5-a80a-17b4ac5cf3cf"
      data-bokeh-model-id=""
      data-bokeh-doc-id=""
  ></script>

You can see the problem: "http://localhost:5006/foo?bar/autoload.js?\.\.\.\.&quot; is not valid with the URL parameter "?bar" in the middle before "/autoload.js".

Basically, any user-supplied URL params need to be detected, and moved to the proper place at the end in the full src URL that is generated. I thought there was an open issue for this, but I can't find it. It would be an immense help if you could make a new issue with all this information (I am putting out several fires at the moment and don't want this to get lost).

In the immediate term, the options I can recommend:

* "fix up" the script tag that is returned to you (hacky, but doable)

* embed using iframes instead of autoload_server

Fixing this should hopefully not be alot of work, I would schedule it for 0.12.5 once there is an issue.

Or, if you are looking for a small OSS contribution, you could poke around here:

  https://github.com/bokeh/bokeh/blob/master/bokeh/embed.py#L408-L425

and look to make a PR to fix this, which would be helpful and appreciated.

Thanks,

Bryan

···

On Jan 17, 2017, at 1:02 PM, Rob Pritchard <[email protected]> wrote:

removing the ?name=%' + company + '%' the app works fine. Are url parameters not allowed in bokeh?

On Monday, January 16, 2017 at 4:42:04 PM UTC-6, Rob Pritchard wrote:
Currently I am using 0.12.3

Embedding without url parameters works fine.
app_path = '/emptydetails_graph'
script = autoload_server(model=None,app_path=app_path, url="http://127.0.0.1:5006/&quot;\)

When I add a parameter:

company = "name"
app_path = '/emptydetails_graph?name=' + "%" + company + "%"
script = autoload_server(model=None, app_path=app_path, url="http://127.0.0.1:5006/&quot;\)

i get an "Uncaught SyntaxError: Unexpected token <" error found in

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Bokeh Application</title>
        
<link rel="stylesheet" href="http://127.0.0.1:5006/static/css/bokeh.min.css?v=882a547e86d77d573fefc67cb37bb345&quot; type="text/css" />
<link rel="stylesheet" href="http://127.0.0.1:5006/static/css/bokeh-widgets.min.css?v=0161cfada7394f178079e5d79c611b3f&quot; type="text/css" />
        
<script type="text/javascript" src="http://127.0.0.1:5006/static/js/bokeh.min.js?v=2489d3f55e068b60ead4375a27399865&quot;&gt;&lt;/script&gt;
<script type="text/javascript" src="http://127.0.0.1:5006/static/js/bokeh-widgets.min.js?v=ce98d7a310ecac8b77374f1ac7c4819a&quot;&gt;&lt;/script&gt;
<script type="text/javascript">
    Bokeh.set_log_level("info");
</script>
        <style>
          html {
            width: 100%;
            height: 100%;
          }
          body {
            width: 90%;
            height: 100%;
            margin: auto;
          }
        </style>
    </head>
    <body>
        
        <div class="bk-root">
            <div class="plotdiv" id="644137de-dbe6-4329-b56f-58f245085659"></div>
        </div>
        
        <script type="text/javascript">
            Bokeh.$(function() {
            Bokeh.safely(function() {
                var docs_json = {};
                var render_items = [{"elementid":"644137de-dbe6-4329-b56f-58f245085659","sessionid":"B90QIGxUPWfZBjWbUlHgAIWB0pejuj9lgo90swPIlHnz","use_for_title":true}];
                
                Bokeh.embed.embed_items(docs_json, render_items, "ws://127.0.0.1:5006/emptydetails_graph/ws");
            });
        });
        </script>
    </body>
</html>

these are both loaded within:
<div class="bk-root">
    {{ the_script|safe }}
</div>

without the embedding http://localhost:5006/emptydetails_graph?name=%sheehy%/autoload.js?bokeh-autoload-element=8a4a408c-f0ab-48f1-a482-d1a7c056e9c7 loads fine.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/8e87caa6-4b59-40a7-b779-bf03623cdb95%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thank you Bryan. I fixed this issue in a really hacky way, but it works finally!

app_path = 'simple_bokeh'
argument = '&name=' + company
url = "http://127.0.0.1:5006/"
script = autoload_server(model=None,
                         app_path="/"+app_path ,
                         url= url)

#split script to get the ID
script_split = script.split('id="')
id = yo_split[1].split('"\n')[0]

#create new src

src = url + app_path + "/autoload.js?bokeh-autoload-element=" + id + argument

#create new script
script = ('<script src="' + src + '" id="' + id + '" data-bokeh-model-id="" data-bokeh-doc-id="" ></script>')

``

I appreciate the help, i'll make a new issue. 

<details class='elided'>
<summary title='Show trimmed content'>&#183;&#183;&#183;</summary>

On Tuesday, January 17, 2017 at 1:32:03 PM UTC-6, Bryan Van de ven wrote:
> The Bokeh server accepts URL parameters when connections are made, and they are available to app code. But the way autoload_server currently constructs URLs is not compatible with URL parameters. You can see this by inspecting the script tag that gets generated:
> 
> 
> 
>         In [5]: print(autoload_server(None, app_path="/foo?bar"))
> 
> 
> 
>         <script
> 
>             src="[http://localhost:5006/foo?bar/autoload.js?bokeh-autoload-element=e56d7065-48cf-4ac5-a80a-17b4ac5cf3cf](http://localhost:5006/foo?bar/autoload.js?bokeh-autoload-element=e56d7065-48cf-4ac5-a80a-17b4ac5cf3cf)"
> 
>             id="e56d7065-48cf-4ac5-a80a-17b4ac5cf3cf"
> 
>             data-bokeh-model-id=""
> 
>             data-bokeh-doc-id=""
> 
>         ></script>
> 
> 
> 
> You can see the problem: "[http://localhost:5006/foo?bar/autoload.js?...](http://localhost:5006/foo?bar/autoload.js?...)." is not valid with the URL parameter "?bar" in the middle before "/autoload.js".
> 
> 
> Basically, any user-supplied URL params need to be detected, and moved to the proper place at the end in the full src URL that is generated. I thought there was an open issue for this, but I can't find it. It would be an immense help if you could make a new issue with all this information (I am putting out several fires at the moment and don't want this to get lost).
> 
> 
> 
> In the immediate term, the options I can recommend:
> 
> 
> 
> * "fix up" the script tag that is returned to you (hacky, but doable)
> 
> 
> 
> * embed using iframes instead of autoload_server
> 
> 
> 
> Fixing this should hopefully not be alot of work, I would schedule it for 0.12.5 once there is an issue.
> 
> 
> Or, if you are looking for a small OSS contribution, you could poke around here:
> 
> 
> 
>         [https://github.com/bokeh/bokeh/blob/master/bokeh/embed.py#L408-L425](https://github.com/bokeh/bokeh/blob/master/bokeh/embed.py#L408-L425)
> 
> 
> 
> and look to make a PR to fix this, which would be helpful and appreciated.
> 
> 
> 
> Thanks,
> 
> 
> 
> Bryan
> 
> 
> > On Jan 17, 2017, at 1:02 PM, Rob Pritchard <[email protected]> wrote:
> 
> >
> > removing the ?name=%' + company + '%' the app works fine. Are url parameters not allowed in bokeh?  
> 
> >
> >
> > On Monday, January 16, 2017 at 4:42:04 PM UTC-6, Rob Pritchard wrote:
> 
> > Currently I am using 0.12.3
> 
> >
> > Embedding without url parameters works fine.
> 
> > app_path = '/emptydetails_graph'
> 
> > script = autoload_server(model=None,app_path=app_path, url="[http://127.0.0.1:5006/](http://127.0.0.1:5006/)")
> 
> >
> >
> > When I add a parameter:
> 
> >
> > company = "name"
> 
> > app_path = '/emptydetails_graph?name=' + "%" + company + "%"
> 
> > script = autoload_server(model=None, app_path=app_path, url="[http://127.0.0.1:5006/](http://127.0.0.1:5006/)")
> >
> > i get an "Uncaught SyntaxError: Unexpected token <" error found in
> 
> >
> > <!DOCTYPE html>
> 
> > <html lang="en">
> 
> >     <head>
> 
> >         <meta charset="utf-8">
> 
> >         <title>Bokeh Application</title>
> 
> >        
> > <link rel="stylesheet" href="[http://127.0.0.1:5006/static/css/bokeh.min.css?v=882a547e86d77d573fefc67cb37bb345](http://127.0.0.1:5006/static/css/bokeh.min.css?v=882a547e86d77d573fefc67cb37bb345)" type="text/css" />
> 
> > <link rel="stylesheet" href="[http://127.0.0.1:5006/static/css/bokeh-widgets.min.css?v=0161cfada7394f178079e5d79c611b3f](http://127.0.0.1:5006/static/css/bokeh-widgets.min.css?v=0161cfada7394f178079e5d79c611b3f)" type="text/css" />
> 
> >        
> > <script type="text/javascript" src="[http://127.0.0.1:5006/static/js/bokeh.min.js?v=2489d3f55e068b60ead4375a27399865](http://127.0.0.1:5006/static/js/bokeh.min.js?v=2489d3f55e068b60ead4375a27399865)"></script>
> 
> > <script type="text/javascript" src="[http://127.0.0.1:5006/static/js/bokeh-widgets.min.js?v=ce98d7a310ecac8b77374f1ac7c4819a](http://127.0.0.1:5006/static/js/bokeh-widgets.min.js?v=ce98d7a310ecac8b77374f1ac7c4819a)"></script>
> 
> > <script type="text/javascript">
> 
> >     Bokeh.set_log_level("info");
> 
> > </script>
> 
> >         <style>
> 
> >           html {
> 
> >             width: 100%;
> 
> >             height: 100%;
> 
> >           }
> 
> >           body {
> 
> >             width: 90%;
> 
> >             height: 100%;
> 
> >             margin: auto;
> 
> >           }
> 
> >         </style>
> 
> >     </head>
> 
> >     <body>
> 
> >        
> >         <div class="bk-root">
> 
> >             <div class="plotdiv" id="644137de-dbe6-4329-b56f-58f245085659"></div>
> 
> >         </div>
> 
> >        
> >         <script type="text/javascript">
> 
> >             Bokeh.$(function() {
> 
> >             Bokeh.safely(function() {
> 
> >                 var docs_json = {};
> 
> >                 var render_items = [{"elementid":"644137de-dbe6-4329-b56f-58f245085659","sessionid":"B90QIGxUPWfZBjWbUlHgAIWB0pejuj9lgo90swPIlHnz","use_for_title":true}];
> 
> >                
> >                 Bokeh.embed.embed_items(docs_json, render_items, "ws://[127.0.0.1:5006/emptydetails_graph/ws](http://127.0.0.1:5006/emptydetails_graph/ws)");
> 
> >             });
> 
> >         });
> 
> >         </script>
> 
> >     </body>
> 
> > </html>
> 
> >
> >
> >
> >
> > these are both loaded within:
> 
> > <div class="bk-root">
> 
> >     {{ the_script|safe }}
> 
> > </div>
> 
> >
> >
> > without the embedding [http://localhost:5006/emptydetails_graph?name=%sheehy%/autoload.js?bokeh-autoload-element=8a4a408c-f0ab-48f1-a482-d1a7c056e9c7](http://localhost:5006/emptydetails_graph?name=%sheehy%/autoload.js?bokeh-autoload-element=8a4a408c-f0ab-48f1-a482-d1a7c056e9c7) loads fine.
> 
> >
> >
> >
> >
> >
> >
> >
> >
> > --
> > You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> 
> > To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
> 
> > To post to this group, send email to [email protected].
> 
> > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/8e87caa6-4b59-40a7-b779-bf03623cdb95%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/8e87caa6-4b59-40a7-b779-bf03623cdb95%40continuum.io).
> 
> > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).
> 
> 
>

</details>