Erreur STRIPE_API_KEY lors du lancement du serveur avec une clé API de test
J'ai cette erreur suivante lorsque je mets la clé api test que j'ai copié sur stripe:
(env_cha) PS D:\Mes Projets\Chaïma> py manage.py runserver
Invalid line: STRIPE_API_KEY = "nepasmontrer"
Invalid line: STRIPE_API_KEY = "nepasmontrer"
Invalid line: STRIPE_API_KEY = "nepasmontrer"
Traceback (most recent call last):
File "D:\Mes Projets\Chaïma\env_cha\Lib\site-packages\environ\environ.py", line 409, in get_value
value = self.ENVIRON[var_name]
~~~~~~~~~~~~^^^^^^^^^^
File "<frozen os="">", line 716, in __getitem__
KeyError: 'STRIPE_API_KEY'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\Mes Projets\Chaïma\manage.py", line 22, in <module>
main()
~~~~^^
File "D:\Mes Projets\Chaïma\manage.py", line 18, in main
execute_from_command_line(sys.argv)
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
File "D:\Mes Projets\Chaïma\env_cha\Lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
utility.execute()
~~~~~~~~~~~~~~~^^
File "D:\Mes Projets\Chaïma\env_cha\Lib\site-packages\django\core\management\__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
File "D:\Mes Projets\Chaïma\env_cha\Lib\site-packages\django\core\management\base.py", line 416, in run_from_argv
self.execute(*args, **cmd_options)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "D:\Mes Projets\Chaïma\env_cha\Lib\site-packages\django\core\management\commands\runserver.py", line 69, in execute
super().execute(*args, **options)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
File "D:\Mes Projets\Chaïma\env_cha\Lib\site-packages\django\core\management\base.py", line 460, in execute
output = self.handle(*args, **options)
File "D:\Mes Projets\Chaïma\env_cha\Lib\site-packages\django\core\management\commands\runserver.py", line 80, in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
^^^^^^^^^^^^^^
File "D:\Mes Projets\Chaïma\env_cha\Lib\site-packages\django\conf\__init__.py", line 81, in __getattr__
self._setup(name)
~~~~~~~~~~~^^^^^^
File "D:\Mes Projets\Chaïma\env_cha\Lib\site-packages\django\conf\__init__.py", line 68, in _setup
self._wrapped = Settings(settings_module)
~~~~~~~~^^^^^^^^^^^^^^^^^
File "D:\Mes Projets\Chaïma\env_cha\Lib\site-packages\django\conf\__init__.py", line 166, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Users\ulric\AppData\Local\Programs\Python\Python313\Lib\importlib\__init__.py", line 88, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap="">", line 1387, in _gcd_import
File "<frozen importlib._bootstrap="">", line 1360, in _find_and_load
File "<frozen importlib._bootstrap="">", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap="">", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external="">", line 1022, in exec_module
File "<frozen importlib._bootstrap="">", line 488, in _call_with_frames_removed
File "D:\Mes Projets\Chaïma\chacha\settings.py", line 139, in <module>
STRIPE_API_KEY = env("STRIPE_API_KEY")
File "D:\Mes Projets\Chaïma\env_cha\Lib\site-packages\environ\environ.py", line 207, in __call__
return self.get_value(
~~~~~~~~~~~~~~^
var,
^^^^
...<2 lines>...
parse_default=parse_default
^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "D:\Mes Projets\Chaïma\env_cha\Lib\site-packages\environ\environ.py", line 413, in get_value
raise ImproperlyConfigured(error_msg) from exc
django.core.exceptions.ImproperlyConfigured: Set the STRIPE_API_KEY environment variable
(env_cha) PS D:\Mes Projets\Chaïma>
Bonjour,
J'ai caché les clés qui étaient affichées, ça doit rester confidentiel surtout.
Le fichier .env est bien créé ? avec la bonne variable à l'intérieur ?
A quel endroit se trouve le fichier .env ? Est-ce qu'il n'y a pas d'espace dans ce fichier ? C'est très sensible.
python environ ou django environ sont bien installés ?
Merci pour le rappel à propos des clés
Oui je crois avoir bien crée le fichier .env et la variable "STRIPE_API_KEY = "Ma_cle_API";
Le fichier .env se trouve à laa racine du projet
Comme dans la video, j'ai utilisé la commande "pip install django-environ" pour installer la dependance, et voici la version installée: django-environ==0.12.0
Inscris-toi
(c'est gratuit !)
Tu dois créer un compte pour participer aux discussions.
Créer un compte