Unhandled error starting single user spawner

An error occurred while starting jupyterhub, and the error stacks are as follows:

[E 2022-08-08 11:26:51.238 JupyterHub user:817] Unhandled error starting mtp's server: expected str, bytes or os.PathLike object, not NoneType 
    Traceback (most recent call last): 
      File "/opt/huawei/miniconda/envs/python36/lib/python3.6/site-packages/jupyterhub/user.py", line 732, in spawn 
        url = await gen.with_timeout(timedelta(seconds=spawner.start_timeout), f) 
      File "/opt/huawei/miniconda/envs/python36/lib/python3.6/site-packages/jupyterhub/spawner.py", line 1573, in start 
        self.proc = Popen(cmd, **popen_kwargs) 
      File "/opt/huawei/miniconda/envs/python36/lib/python3.6/subprocess.py", line 729, in __init__ 
        restore_signals, start_new_session) 
      File "/opt/huawei/miniconda/envs/python36/lib/python3.6/subprocess.py", line 1275, in _execute_child 
        env_list.append(k + b'=' + os.fsencode(v)) 
      File "/opt/huawei/miniconda/envs/python36/lib/python3.6/os.py", line 800, in fsencode 
        filename = fspath(filename)  # Does type-checking of `filename`. 
    TypeError: expected str, bytes or os.PathLike object, not NoneType 
     
[E 2022-08-08 11:26:51.283 JupyterHub pages:317] Error starting server mtp: expected str, bytes or os.PathLike object, not NoneType 
    Traceback (most recent call last): 
    None: None 

It looks like there is an environment variable set to None instead of a string. Can you share some of your configuration? Especially if you set c.Spawner.environment anywhere.

Config c.Spawner.environment like this @minrk :
Do u mean maybe some of my variables are empty, causing this problem?

ENV_VARIABLES =  [
    # keys of a few env variables
]

variables = {}
for variable in ENV_VARIABLES:
    variables[variable] = os.getenv(variable)

c.Spawner.environment = variables

Yup, that’s it - os.getenv returns None if a variable is unset, and that’s not a valid value to set. You either need to leave them out of Spawner.environment, or set them to a string (empty environment variables are almost always handled the same as unset, but not always!).

This will work:

variables = {}
for variable in ENV_VARIABLES:
    value = os.getenv(variable)
    if value is not None:
        variables[variable] = value
    else:
        print(f"Environment ${variable} not set!")

But! JupyterHub actually has a shortcut for exactly this behavior, called c.Spawner.env_keep:

c.Spawner.env_keep.extend(ENV_VARIABLES)