prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Invalid argument: '--cookie-name=jupyter-hub-token-MYUSERNAME'
  I can't run cells in py notebooks, I got a popup `The kernel appears to have died`
  
  Here's the log running jupyterhub from master branch
  
  ```
  [IPKernelApp] CRITICAL | Bad config encountered during initialization:
  [IPKernelApp] CRITICAL | Invalid argument: '--cookie-name=jupyter-hub-token-ben'
  2014-09-14 20:53:59.865 [SingleUserNotebookApp] WARNING | KernelRestarter: restart failed
  2014-09-14 20:53:59.866 [SingleUserNotebookApp] WARNING | Kernel ec8afdad-2a1e-47f2-8202-d3644832c13e died, removing from map.
  ERROR:root:kernel ec8afdad-2a1e-47f2-8202-d3644832c13e restarted failed!
  
  ```
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `jupyterhub/singleuserapp.py`
  Content:
  ```
  1 #!/usr/bin/env python
  2 """Extend regular notebook server to be aware of multiuser things."""
  3 
  4 # Copyright (c) Jupyter Development Team.
  5 # Distributed under the terms of the Modified BSD License.
  6 
  7 import os
  8 
  9 import requests
  10 
  11 from tornado import ioloop
  12 from tornado import web
  13 
  14 from IPython.utils.traitlets import Unicode
  15 
  16 from IPython.html.notebookapp import NotebookApp
  17 
  18 from IPython.html.utils import url_path_join
  19 
  20 
  21 from distutils.version import LooseVersion as V
  22 
  23 import IPython
  24 if V(IPython.__version__) < V('2.2'):
  25     raise ImportError("JupyterHub Requires IPython >= 2.2, found %s" % IPython.__version__)
  26 
  27 # Define two methods to attach to AuthenticatedHandler,
  28 # which authenticate via the central auth server.
  29 
  30 
  31 def verify_token(self, token):
  32     """monkeypatch method for token verification"""
  33     token_cache = self.settings['token_cache']
  34     if token in token_cache:
  35         # we've seen this token before, don't ask upstream again
  36         return token_cache[token]
  37     
  38     hub_api_url = self.settings['hub_api_url']
  39     hub_api_key = self.settings['hub_api_key']
  40     r = requests.get(url_path_join(
  41         hub_api_url, "authorizations", token,
  42     ),
  43         headers = {'Authorization' : 'token %s' % hub_api_key}
  44     )
  45     if r.status_code == 404:
  46         data = {'user' : ''}
  47     else:
  48         r.raise_for_status()
  49         data = r.json()
  50     token_cache[token] = data
  51     return data
  52 
  53 
  54 def get_current_user(self):
  55     """alternative get_current_user to query the central server"""
  56     my_user = self.settings['user']
  57     token = self.get_cookie(self.cookie_name, '')
  58     if token:
  59         auth_data = self.verify_token(token)
  60         if not auth_data:
  61             # treat invalid token the same as no token
  62             return None
  63         user = auth_data['user']
  64         if user == my_user:
  65             return user
  66         else:
  67             return None
  68     else:
  69         self.log.debug("No token cookie")
  70         return None
  71 
  72 
  73 # register new hub related command-line aliases
  74 aliases = NotebookApp.aliases.get_default_value()
  75 aliases.update({
  76     'user' : 'SingleUserNotebookApp.user',
  77     'cookie-name': 'SingleUserNotebookApp.cookie_name',
  78     'hub-prefix': 'SingleUserNotebookApp.hub_prefix',
  79     'hub-api-url': 'SingleUserNotebookApp.hub_api_url',
  80     'base-url': 'SingleUserNotebookApp.base_url',
  81 })
  82 
  83 
  84 class SingleUserNotebookApp(NotebookApp):
  85     """A Subclass of the regular NotebookApp that is aware of the parent multiuser context."""
  86     user = Unicode(config=True)
  87     cookie_name = Unicode(config=True)
  88     hub_prefix = Unicode(config=True)
  89     hub_api_url = Unicode(config=True)
  90     aliases = aliases
  91     open_browser = False
  92     
  93     def _confirm_exit(self):
  94         # disable the exit confirmation for background notebook processes
  95         ioloop.IOLoop.instance().stop()
  96     
  97     def init_webapp(self):
  98         # monkeypatch authentication to use the hub
  99         from IPython.html.base.handlers import AuthenticatedHandler
  100         AuthenticatedHandler.verify_token = verify_token
  101         AuthenticatedHandler.get_current_user = get_current_user
  102         
  103         # load the hub related settings into the tornado settings dict
  104         env = os.environ
  105         s = self.webapp_settings
  106         s['token_cache'] = {}
  107         s['user'] = self.user
  108         s['hub_api_key'] = env.pop('JPY_API_TOKEN', '')
  109         s['cookie_secret'] = env.pop('JPY_COOKIE_SECRET', '')
  110         s['cookie_name'] = self.cookie_name
  111         s['login_url'] = url_path_join(self.hub_prefix, 'login')
  112         s['hub_api_url'] = self.hub_api_url
  113         super(SingleUserNotebookApp, self).init_webapp()
  114 
  115 
  116 def main():
  117     return SingleUserNotebookApp.launch_instance()
  118 
  119 
  120 if __name__ == "__main__":
  121     main()
  122
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/jupyterhub/singleuserapp.py b/jupyterhub/singleuserapp.py
  --- a/jupyterhub/singleuserapp.py
  +++ b/jupyterhub/singleuserapp.py
  @@ -94,6 +94,11 @@
           # disable the exit confirmation for background notebook processes
           ioloop.IOLoop.instance().stop()
       
  +    def init_kernel_argv(self):
  +        """construct the kernel arguments"""
  +        # FIXME: This is 2.x-compat, remove when 3.x is requred
  +        self.kernel_argv = ["--profile-dir", self.profile_dir.location]
  +    
       def init_webapp(self):
           # monkeypatch authentication to use the hub
           from IPython.html.base.handlers import AuthenticatedHandler
  
verification_info: {"golden_diff": "diff --git a/jupyterhub/singleuserapp.py b/jupyterhub/singleuserapp.py\n--- a/jupyterhub/singleuserapp.py\n+++ b/jupyterhub/singleuserapp.py\n@@ -94,6 +94,11 @@\n         # disable the exit confirmation for background notebook processes\n         ioloop.IOLoop.instance().stop()\n     \n+    def init_kernel_argv(self):\n+        \"\"\"construct the kernel arguments\"\"\"\n+        # FIXME: This is 2.x-compat, remove when 3.x is requred\n+        self.kernel_argv = [\"--profile-dir\", self.profile_dir.location]\n+    \n     def init_webapp(self):\n         # monkeypatch authentication to use the hub\n         from IPython.html.base.handlers import AuthenticatedHandler\n", "issue": "Invalid argument: '--cookie-name=jupyter-hub-token-MYUSERNAME'\nI can't run cells in py notebooks, I got a popup `The kernel appears to have died`\n\nHere's the log running jupyterhub from master branch\n\n```\n[IPKernelApp] CRITICAL | Bad config encountered during initialization:\n[IPKernelApp] CRITICAL | Invalid argument: '--cookie-name=jupyter-hub-token-ben'\n2014-09-14 20:53:59.865 [SingleUserNotebookApp] WARNING | KernelRestarter: restart failed\n2014-09-14 20:53:59.866 [SingleUserNotebookApp] WARNING | Kernel ec8afdad-2a1e-47f2-8202-d3644832c13e died, removing from map.\nERROR:root:kernel ec8afdad-2a1e-47f2-8202-d3644832c13e restarted failed!\n\n```\n\n", "before_files": [{"content": "#!/usr/bin/env python\n\"\"\"Extend regular notebook server to be aware of multiuser things.\"\"\"\n\n# Copyright (c) Jupyter Development Team.\n# Distributed under the terms of the Modified BSD License.\n\nimport os\n\nimport requests\n\nfrom tornado import ioloop\nfrom tornado import web\n\nfrom IPython.utils.traitlets import Unicode\n\nfrom IPython.html.notebookapp import NotebookApp\n\nfrom IPython.html.utils import url_path_join\n\n\nfrom distutils.version import LooseVersion as V\n\nimport IPython\nif V(IPython.__version__) < V('2.2'):\n    raise ImportError(\"JupyterHub Requires IPython >= 2.2, found %s\" % IPython.__version__)\n\n# Define two methods to attach to AuthenticatedHandler,\n# which authenticate via the central auth server.\n\n\ndef verify_token(self, token):\n    \"\"\"monkeypatch method for token verification\"\"\"\n    token_cache = self.settings['token_cache']\n    if token in token_cache:\n        # we've seen this token before, don't ask upstream again\n        return token_cache[token]\n    \n    hub_api_url = self.settings['hub_api_url']\n    hub_api_key = self.settings['hub_api_key']\n    r = requests.get(url_path_join(\n        hub_api_url, \"authorizations\", token,\n    ),\n        headers = {'Authorization' : 'token %s' % hub_api_key}\n    )\n    if r.status_code == 404:\n        data = {'user' : ''}\n    else:\n        r.raise_for_status()\n        data = r.json()\n    token_cache[token] = data\n    return data\n\n\ndef get_current_user(self):\n    \"\"\"alternative get_current_user to query the central server\"\"\"\n    my_user = self.settings['user']\n    token = self.get_cookie(self.cookie_name, '')\n    if token:\n        auth_data = self.verify_token(token)\n        if not auth_data:\n            # treat invalid token the same as no token\n            return None\n        user = auth_data['user']\n        if user == my_user:\n            return user\n        else:\n            return None\n    else:\n        self.log.debug(\"No token cookie\")\n        return None\n\n\n# register new hub related command-line aliases\naliases = NotebookApp.aliases.get_default_value()\naliases.update({\n    'user' : 'SingleUserNotebookApp.user',\n    'cookie-name': 'SingleUserNotebookApp.cookie_name',\n    'hub-prefix': 'SingleUserNotebookApp.hub_prefix',\n    'hub-api-url': 'SingleUserNotebookApp.hub_api_url',\n    'base-url': 'SingleUserNotebookApp.base_url',\n})\n\n\nclass SingleUserNotebookApp(NotebookApp):\n    \"\"\"A Subclass of the regular NotebookApp that is aware of the parent multiuser context.\"\"\"\n    user = Unicode(config=True)\n    cookie_name = Unicode(config=True)\n    hub_prefix = Unicode(config=True)\n    hub_api_url = Unicode(config=True)\n    aliases = aliases\n    open_browser = False\n    \n    def _confirm_exit(self):\n        # disable the exit confirmation for background notebook processes\n        ioloop.IOLoop.instance().stop()\n    \n    def init_webapp(self):\n        # monkeypatch authentication to use the hub\n        from IPython.html.base.handlers import AuthenticatedHandler\n        AuthenticatedHandler.verify_token = verify_token\n        AuthenticatedHandler.get_current_user = get_current_user\n        \n        # load the hub related settings into the tornado settings dict\n        env = os.environ\n        s = self.webapp_settings\n        s['token_cache'] = {}\n        s['user'] = self.user\n        s['hub_api_key'] = env.pop('JPY_API_TOKEN', '')\n        s['cookie_secret'] = env.pop('JPY_COOKIE_SECRET', '')\n        s['cookie_name'] = self.cookie_name\n        s['login_url'] = url_path_join(self.hub_prefix, 'login')\n        s['hub_api_url'] = self.hub_api_url\n        super(SingleUserNotebookApp, self).init_webapp()\n\n\ndef main():\n    return SingleUserNotebookApp.launch_instance()\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "jupyterhub/singleuserapp.py"}], "after_files": [{"content": "#!/usr/bin/env python\n\"\"\"Extend regular notebook server to be aware of multiuser things.\"\"\"\n\n# Copyright (c) Jupyter Development Team.\n# Distributed under the terms of the Modified BSD License.\n\nimport os\n\nimport requests\n\nfrom tornado import ioloop\nfrom tornado import web\n\nfrom IPython.utils.traitlets import Unicode\n\nfrom IPython.html.notebookapp import NotebookApp\n\nfrom IPython.html.utils import url_path_join\n\n\nfrom distutils.version import LooseVersion as V\n\nimport IPython\nif V(IPython.__version__) < V('2.2'):\n    raise ImportError(\"JupyterHub Requires IPython >= 2.2, found %s\" % IPython.__version__)\n\n# Define two methods to attach to AuthenticatedHandler,\n# which authenticate via the central auth server.\n\n\ndef verify_token(self, token):\n    \"\"\"monkeypatch method for token verification\"\"\"\n    token_cache = self.settings['token_cache']\n    if token in token_cache:\n        # we've seen this token before, don't ask upstream again\n        return token_cache[token]\n    \n    hub_api_url = self.settings['hub_api_url']\n    hub_api_key = self.settings['hub_api_key']\n    r = requests.get(url_path_join(\n        hub_api_url, \"authorizations\", token,\n    ),\n        headers = {'Authorization' : 'token %s' % hub_api_key}\n    )\n    if r.status_code == 404:\n        data = {'user' : ''}\n    else:\n        r.raise_for_status()\n        data = r.json()\n    token_cache[token] = data\n    return data\n\n\ndef get_current_user(self):\n    \"\"\"alternative get_current_user to query the central server\"\"\"\n    my_user = self.settings['user']\n    token = self.get_cookie(self.cookie_name, '')\n    if token:\n        auth_data = self.verify_token(token)\n        if not auth_data:\n            # treat invalid token the same as no token\n            return None\n        user = auth_data['user']\n        if user == my_user:\n            return user\n        else:\n            return None\n    else:\n        self.log.debug(\"No token cookie\")\n        return None\n\n\n# register new hub related command-line aliases\naliases = NotebookApp.aliases.get_default_value()\naliases.update({\n    'user' : 'SingleUserNotebookApp.user',\n    'cookie-name': 'SingleUserNotebookApp.cookie_name',\n    'hub-prefix': 'SingleUserNotebookApp.hub_prefix',\n    'hub-api-url': 'SingleUserNotebookApp.hub_api_url',\n    'base-url': 'SingleUserNotebookApp.base_url',\n})\n\n\nclass SingleUserNotebookApp(NotebookApp):\n    \"\"\"A Subclass of the regular NotebookApp that is aware of the parent multiuser context.\"\"\"\n    user = Unicode(config=True)\n    cookie_name = Unicode(config=True)\n    hub_prefix = Unicode(config=True)\n    hub_api_url = Unicode(config=True)\n    aliases = aliases\n    open_browser = False\n    \n    def _confirm_exit(self):\n        # disable the exit confirmation for background notebook processes\n        ioloop.IOLoop.instance().stop()\n    \n    def init_kernel_argv(self):\n        \"\"\"construct the kernel arguments\"\"\"\n        # FIXME: This is 2.x-compat, remove when 3.x is requred\n        self.kernel_argv = [\"--profile-dir\", self.profile_dir.location]\n    \n    def init_webapp(self):\n        # monkeypatch authentication to use the hub\n        from IPython.html.base.handlers import AuthenticatedHandler\n        AuthenticatedHandler.verify_token = verify_token\n        AuthenticatedHandler.get_current_user = get_current_user\n        \n        # load the hub related settings into the tornado settings dict\n        env = os.environ\n        s = self.webapp_settings\n        s['token_cache'] = {}\n        s['user'] = self.user\n        s['hub_api_key'] = env.pop('JPY_API_TOKEN', '')\n        s['cookie_secret'] = env.pop('JPY_COOKIE_SECRET', '')\n        s['cookie_name'] = self.cookie_name\n        s['login_url'] = url_path_join(self.hub_prefix, 'login')\n        s['hub_api_url'] = self.hub_api_url\n        super(SingleUserNotebookApp, self).init_webapp()\n\n\ndef main():\n    return SingleUserNotebookApp.launch_instance()\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "jupyterhub/singleuserapp.py"}]}