'TypeError: Consumer key must be string or bytes, not NoneType when authentication

Planning to use variables to authorize tweepy with Twitter's API, but it shows the following:
TypeError: Consumer key must be string or bytes, not NoneType when authentication

Code below:

import tweepy
import os

consumera = os.environ.get('TWICK')
consumerb = os.environ.get('TWICS')
accessa = os.environ.get('TWIAT')
accessb = os.environ.get('TWIATS')

auth = tweepy.OAuthHandler(consumera, consumerb)
auth.set_access_token(accessa, accessb)

api = tweepy.API(auth)

status = api.update_status(status="Test tweet.")

I've tried using other authentication methods, such as:

consumera = os.environ.get('TWICK')
consumerb = os.environ.get('TWICS')
accessa = os.environ.get('TWIAT')
accessb = os.environ.get('TWIATS')

client = tweepy.Client(consumer_key=consumera,
                       consumer_secret=consumerb,
                       access_token=accessa,
                       access_token_secret=accessb
                       )

Any fix?

Additional info: I was planning to run it through GitHub actions but without exposing the keys in the source code - and I put all the keys as secrets, so it requires environmental access. Tested on Ubuntu (both local and under GitHub Actions), but no luck.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source