-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import requests | ||
|
||
|
||
def check_bookstack_api(base_url, token_id, token_secret): | ||
# Construct the API endpoint URL | ||
api_url = f"{base_url.rstrip('/')}/api/books" | ||
|
||
# Set up the headers with the API credentials | ||
headers = { | ||
"Authorization": f"Token {token_id}:{token_secret}", | ||
"Accept": "application/json", | ||
} | ||
|
||
try: | ||
# Make a GET request to the API | ||
response = requests.get(api_url, headers=headers) | ||
|
||
# Check the response status code | ||
if response.status_code == 200: | ||
print("API key is valid and not expired.") | ||
return True | ||
elif response.status_code == 401: | ||
print("API key is invalid or has expired.") | ||
return False | ||
else: | ||
print(f"Unexpected response. Status code: {response.status_code}") | ||
print(f"Response content: {response.text}") | ||
return False | ||
|
||
except requests.RequestException as e: | ||
print(f"An error occurred while making the request: {e}") | ||
return False | ||
|
||
|
||
if __name__ == "__main__": | ||
base_url = "https://kb.yuma1.com" | ||
token_id = "MK4OgjOLEEhvHQf0cEwjYr1kVSYZoGa7" | ||
token_secret = "kV6a8dnHOwAzAjL22jTMJHDhxWhqkeSw" | ||
|
||
check_bookstack_api(base_url, token_id, token_secret) |