jupyter / kernel_gateway_demos

Demos associated with the kernel gateway incubator project
BSD 3-Clause "New" or "Revised" License
152 stars 76 forks source link

KG_ENV_WHITELIST error #49

Closed prashant182 closed 7 years ago

prashant182 commented 7 years ago
  1. Running Spark kernels in separate docker container. [Jupyter/all-spark-notebook]
  2. Running Jupyter with Nb2Kg in different container.

issue

File "/usr/local/lib/python3.4/dist-packages/notebook/base/handlers.py", line 503, in wrapper
        result = yield gen.maybe_future(method(self, *args, **kwargs))
      File "/usr/local/lib/python3.4/dist-packages/tornado/gen.py", line 1008, in run
        value = future.result()
      File "/usr/local/lib/python3.4/dist-packages/tornado/concurrent.py", line 232, in result
        raise_exc_info(self._exc_info)
      File "<string>", line 3, in raise_exc_info
      File "/usr/local/lib/python3.4/dist-packages/tornado/gen.py", line 1014, in run
        yielded = self.gen.throw(*exc_info)
      File "/usr/local/lib/python3.4/dist-packages/notebook/services/sessions/handlers.py", line 75, in post
        type=mtype))
      File "/usr/local/lib/python3.4/dist-packages/tornado/gen.py", line 1008, in run
        value = future.result()
      File "/usr/local/lib/python3.4/dist-packages/tornado/concurrent.py", line 232, in result
        raise_exc_info(self._exc_info)
      File "<string>", line 3, in raise_exc_info
      File "/usr/local/lib/python3.4/dist-packages/tornado/gen.py", line 1014, in run
        yielded = self.gen.throw(*exc_info)
      File "/usr/local/lib/python3.4/dist-packages/nb2kg/managers.py", line 320, in create_session
        session_id, path, name, type, kernel_name,
      File "/usr/local/lib/python3.4/dist-packages/tornado/gen.py", line 1008, in run
        value = future.result()
      File "/usr/local/lib/python3.4/dist-packages/tornado/concurrent.py", line 232, in result
        raise_exc_info(self._exc_info)
      File "<string>", line 3, in raise_exc_info
      File "/usr/local/lib/python3.4/dist-packages/tornado/gen.py", line 1014, in run
        yielded = self.gen.throw(*exc_info)
      File "/usr/local/lib/python3.4/dist-packages/notebook/services/sessions/sessionmanager.py", line 92, in start_kernel_for_session
        self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
      File "/usr/local/lib/python3.4/dist-packages/tornado/gen.py", line 1008, in run
        value = future.result()
      File "/usr/local/lib/python3.4/dist-packages/tornado/concurrent.py", line 232, in result
        raise_exc_info(self._exc_info)
      File "<string>", line 3, in raise_exc_info
      File "/usr/local/lib/python3.4/dist-packages/tornado/gen.py", line 282, in wrapper
        yielded = next(result)
      File "/usr/local/lib/python3.4/dist-packages/nb2kg/managers.py", line 116, in start_kernel
        'env': {k:v for (k,v) in dict(os.environ).items() if k.startswith('KERNEL_') or k in os.environ['KG_ENV_WHITELIST'].split(",")}
      File "/usr/local/lib/python3.4/dist-packages/nb2kg/managers.py", line 116, in <dictcomp>
        'env': {k:v for (k,v) in dict(os.environ).items() if k.startswith('KERNEL_') or k in os.environ['KG_ENV_WHITELIST'].split(",")}
      File "/usr/lib/python3.4/os.py", line 633, in __getitem__
        raise KeyError(key) from None
    KeyError: 'KG_ENV_WHITELIST'
KharbandaArush commented 7 years ago

I also faced this error, as a workaround i created a blank environment variable.

LK-Tmac1 commented 7 years ago

On my PR #55 I already fixed this bug by using os.environ.get('KG_ENV_WHITELIST', '') instead of os.environ['KG_ENV_WHITELIST'].

kevin-bates commented 7 years ago

Closing this issue as it was fixed by PR #55. Thanks @liukun1016!

aafaq146 commented 4 years ago

Traceback (most recent call last): File "app.py", line 9, in api = TwitterClient('Afridi') File "C:\Users\Aafaq Ahmad\Aafaq Sahib\twitter.py", line 16, in init consumer_key = os.environ['JQM5TMwSPV6fKHmfbSBNKgE2O'] File "C:\Users\Aafaq Ahmad\lib\os.py", line 675, in getitem raise KeyError(key) from None KeyError: 'JQM5TMwSPV6fKHmfbSBNKgE2O' i face this issue why plz help

aafaq146 commented 4 years ago

anyone help me to resolve this issue

Traceback (most recent call last): File "app.py", line 9, in api = TwitterClient('Afridi') File "C:\Users\Aafaq Ahmad\Aafaq Sahib\twitter.py", line 16, in init consumer_key = os.environ['JQM5TMwSPV6fKHmfbSBNKgE2O'] File "C:\Users\Aafaq Ahmad\lib\os.py", line 675, in getitem raise KeyError(key) from None KeyError: 'JQM5TMwSPV6fKHmfbSBNKgE2O'

kevin-bates commented 4 years ago

Hi @aafaq146 - your issue description doesn't appear to be related to Kernel Gateway. Where are you encountering this issue? If anything, this appears related to the TwitterClient package and you'll get more traction opening an issue with whomever produced TwitterClient.

Your immediate issue is that you're trying to fetch an environment variable that is not in the current environment. I would recommend using getenv instead, then check for a None result to determine if the variable does not exist - or add exception handling...

Using os.getenv()...

consumer_key = os.getenv('JQM5TMwSPV6fKHmfbSBNKgE2O')
if consumer_key is None:
    # Perform what should happen when variable does not exist
...

or with exception handling...

try:
    consumer_key = os.environ['JQM5TMwSPV6fKHmfbSBNKgE2O']
except KeyError:
    # Key does not exist
   pass

if consumer_key is None:
    # Perform what should happen when variable does not exist
...