Last active
March 4, 2020 01:14
-
-
Save agritheory/40a995f24c54d9cd06a94dba991c0605 to your computer and use it in GitHub Desktop.
Frappe Token Authorization Example
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
from requests import request | |
from base64 import b64encode | |
api_secret = get_decrypted_password("User", "example_username", "api_secret") # this is an internal frappe method | |
token = frappe.get_value("User", "example_username", "api_key") # this is an internal frappe method | |
url = "https://" + subdomain + ".some_domain.com" | |
headers = { | |
"Content-Type": "application/json", | |
"Authorization": "Basic " | |
+ b64encode(bytes(token + ":" + api_secret, "ascii")).decode("ascii"), | |
} | |
r = request("POST", url + "/api/resource/Item", data=data, headers=headers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment