0

I've recently had a problem with (i think) the os module in python:

Traceback (most recent call last):
  File "main.py", line 9, in <module>
    api = getApi(os.environ['consumer_key'], os.environ['consumer_secret'], os.environ['access_token_key'], os.environ['access_token_secret'])
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\os.py", line 681, in __getitem__
    raise KeyError(key) from None
KeyError: 'consumer_key'

my code of main.py is:

from config import getApi
import os
import sys
import time
print()



api = getApi(os.environ['consumer_key'], os.environ['consumer_secret'], os.environ['access_token_key'], os.environ['access_token_secret'])

my code of config.py is

import twitter
import os

def getApi(consumer_key, consumer_secret, access_token_key, access_token_secret):
    return twitter.Api(consumer_key='*********',
        consumer_secret='*********',
        access_token_key='*********',
        access_token_secret='*********')

Send tweets with the postUpdate is possible if I write the keys in the main.py but when I put the keys in the config.py, it don't works

Can anyone help me please ?

Marcucus _
  • 88
  • 10

1 Answers1

0

It's not an error with the os module, the keys simply aren't in the enviroment. If you're using a .env file you should use a module like dotenv to load the file.

Łukasz Kwieciński
  • 14,992
  • 4
  • 21
  • 39