Created
November 16, 2023 08:10
-
-
Save KabakiAntony/60716325dac37638ea1029907c417ddd to your computer and use it in GitHub Desktop.
get mpesa access token function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_mpesa_access_token(self): | |
try: | |
res = requests.get( | |
self.access_token_url, | |
auth=HTTPBasicAuth(self.consumer_key, self.consumer_secret), | |
) | |
token = res.json()['access_token'] | |
self.headers = { | |
"Authorization": f"Bearer {token}", | |
"Content-Type": "application/json" | |
} | |
except Exception as e: | |
print(str(e), "error getting access token") | |
raise e | |
return token |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment