Skip to content

Instantly share code, notes, and snippets.

@agritheory
Last active March 4, 2020 01:14
Show Gist options
  • Save agritheory/40a995f24c54d9cd06a94dba991c0605 to your computer and use it in GitHub Desktop.
Save agritheory/40a995f24c54d9cd06a94dba991c0605 to your computer and use it in GitHub Desktop.
Frappe Token Authorization Example
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