[TLJH] How to set env vars for users _after_ but not for the spawner?

Does setting no_proxy to include the hub ip work? On TLJH, that should be 127.0.0.1, I believe, so this config:

c.Spawner.environment = {
  "http_proxy": "http://your proxy",
  "https_proxy": "https://your proxy",
  "no_proxy": "127.0.0.1,localhost",
}

ought to work, assuming the http client(s) in question supports $no_proxy. Which are they, btw?

If you still need to, kernelspecs can define an env dict to specify any environment variables that should be set when launching the kernel, for example:

{
 "argv": ["python3", "-m", "IPython.kernel",
          "-f", "{connection_file}"],
 "display_name": "Python 3",
 "language": "python",
 "env": {"http_proxy": "..."}
}

so patching kernelspec .json files is one way to set envs. Another is to subclass MappingKernelManager, extending .start_kernel() to pass additional env variables at kernel start time.

But modifying kernelspecs won’t affect terminals, so the no_proxy exception for the hub ip is probably preferable, if it works.

3 Likes