def _compute_notebook_server_base_url():
    """Figure out the base_url of the current Jupyter notebook server.

    Copied from
    https://github.com/jupyter/notebook/issues/3156#issuecomment-401119433
    with miniscule changes. This is gross, but appears to be the best
    available option right now.

    """
    import ipykernel
    import json
    from notebook.notebookapp import list_running_servers
    import re
    import requests
    kernel_id = re.search('kernel-(.*).json', ipykernel.connect.
        get_connection_file()).group(1)
    for s in list_running_servers():
        response = requests.get(requests.compat.urljoin(s['url'],
            'api/sessions'), params={'token': s.get('token', '')})
        for n in json.loads(response.text):
            if n['kernel']['id'] == kernel_id:
                return s['base_url']
    raise Exception(
        'cannot locate our notebook server; is this code running in a Jupyter kernel?'
        )
