You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to turn off the interpolation feature because I don't use it, but instead, take the raw value of the variable. The solution to disable interpolation in the docs doesn't seem to work.
Here are two examples of getting the raw value of a variable FOO that starts with $, using the latest version 0.11.2
Defining the variable in the .env
# .env file
FOO="$BAR"
# pythonIn [1]: importenvironIn [2]: env=environ.Env(interpolate=False)
In [3]: env('FOO')
---------------------------------------------------------------------------KeyErrorTraceback (mostrecentcalllast)
File/usr/local/lib/python3.9/site-packages/environ/environ.py:388, inEnv.get_value(self, var, cast, default, parse_default)
387try:
-->388value=self.ENVIRON[var_name]
389exceptKeyErrorasexc:
File/usr/local/lib/python3.9/os.py:679, in_Environ.__getitem__(self, key)
677exceptKeyError:
678# raise KeyError with the original key value-->679raiseKeyError(key) fromNone680returnself.decodevalue(value)
KeyError: 'BAR'Theaboveexceptionwasthedirectcauseofthefollowingexception:
ImproperlyConfiguredTraceback (mostrecentcalllast)
CellIn[2], line31importenviron2env=environ.Env(interpolate=False)
---->3env('FOO')
File/usr/local/lib/python3.9/site-packages/environ/environ.py:199, inEnv.__call__(self, var, cast, default, parse_default)
198def__call__(self, var, cast=None, default=NOTSET, parse_default=False):
-->199returnself.get_value(
200var,
201cast=cast,
202default=default,
203parse_default=parse_default204 )
File/usr/local/lib/python3.9/site-packages/environ/environ.py:401, inEnv.get_value(self, var, cast, default, parse_default)
399ifhasattr(value, 'startswith') andvalue.startswith(prefix):
400value=value.lstrip(prefix)
-->401value=self.get_value(value, cast=cast, default=default)
403ifself.escape_proxyandhasattr(value, 'replace'):
404value=value.replace(escape, prefix)
File/usr/local/lib/python3.9/site-packages/environ/environ.py:392, inEnv.get_value(self, var, cast, default, parse_default)
390ifdefaultisself.NOTSET:
391error_msg=f'Set the {var} environment variable'-->392raiseImproperlyConfigured(error_msg) fromexc394value=default396# Resolve any proxied valuesImproperlyConfigured: SettheBARenvironmentvariable
Same use case but populating from default values
In [1]: import environ
In [2]: env = environ.Env(interpolate=False, FOO=('str', '$BAR'))
In [3]: env('FOO')
---------------------------------------------------------------------------
RecursionError Traceback (most recent call last)
Cell In[17], line 1
----> 1 env('FOO')
File /usr/local/lib/python3.9/site-packages/environ/environ.py:199, in Env.__call__(self, var, cast, default, parse_default)
198def__call__(self, var, cast=None, default=NOTSET, parse_default=False):
--> 199 return self.get_value(
200 var,
201 cast=cast,
202 default=default,
203 parse_default=parse_default
204 )
File /usr/local/lib/python3.9/site-packages/environ/environ.py:401, in Env.get_value(self, var, cast, default, parse_default)
399ifhasattr(value, 'startswith') and value.startswith(prefix):
400 value = value.lstrip(prefix)
--> 401 value = self.get_value(value, cast=cast, default=default)
403ifself.escape_proxy andhasattr(value, 'replace'):
404 value = value.replace(escape, prefix)
File /usr/local/lib/python3.9/site-packages/environ/environ.py:401, in Env.get_value(self, var, cast, default, parse_default)
399ifhasattr(value, 'startswith') and value.startswith(prefix):
400 value = value.lstrip(prefix)
--> 401 value = self.get_value(value, cast=cast, default=default)
403ifself.escape_proxy andhasattr(value, 'replace'):
404 value = value.replace(escape, prefix)
[... skipping similar frames: Env.get_value at line 401 (2977 times)]
File /usr/local/lib/python3.9/site-packages/environ/environ.py:401, in Env.get_value(self, var, cast, default, parse_default)
399ifhasattr(value, 'startswith') and value.startswith(prefix):
400 value = value.lstrip(prefix)
--> 401 value = self.get_value(value, cast=cast, default=default)
403ifself.escape_proxy andhasattr(value, 'replace'):
404 value = value.replace(escape, prefix)
File /usr/local/lib/python3.9/site-packages/environ/environ.py:388, in Env.get_value(self, var, cast, default, parse_default)
385 cast = var_info
387try:
--> 388 value = self.ENVIRON[var_name]
389exceptKeyErroras exc:
390if default isself.NOTSET:
File /usr/local/lib/python3.9/os.py:676, in _Environ.__getitem__(self, key)
674def__getitem__(self, key):
675try:
--> 676 value = self._data[self.encodekey(key)]
677exceptKeyError:
678# raise KeyError with the original key value679raiseKeyError(key) fromNone
File /usr/local/lib/python3.9/os.py:755, in _createenviron.<locals>.encode(value)
754defencode(value):
--> 755 if not isinstance(value, str):
756raiseTypeError("str expected, not %s"%type(value).__name__)
757return value.encode(encoding, 'surrogateescape')
RecursionError: maximum recursion depth exceeded while calling a Python object
The text was updated successfully, but these errors were encountered:
amatmv
changed the title
Does disabling the interpolation option work?
Does the option to disable interpolation even work?
Jun 19, 2024
I want to turn off the interpolation feature because I don't use it, but instead, take the raw value of the variable. The solution to disable interpolation in the docs doesn't seem to work.
Here are two examples of getting the raw value of a variable
FOO
that starts with$
, using the latest version0.11.2
Defining the variable in the .env
Same use case but populating from default values
The text was updated successfully, but these errors were encountered: