Skip to content

Instantly share code, notes, and snippets.

@KabakiAntony
Created November 16, 2023 08:10
Show Gist options
  • Save KabakiAntony/60716325dac37638ea1029907c417ddd to your computer and use it in GitHub Desktop.
Save KabakiAntony/60716325dac37638ea1029907c417ddd to your computer and use it in GitHub Desktop.
get mpesa access token function
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