36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Confirm Woo endpoints work with browser-like User-Agent + existing Woo Basic Auth."""
|
|
import os
|
|
|
|
import requests
|
|
from requests.auth import HTTPBasicAuth
|
|
|
|
BROWSER_HEADERS = {
|
|
"User-Agent": "Mozilla/5.0 (compatible; AZA-WooDiagnostic/1.0; +https://api.aza-medwork.ch)",
|
|
"Accept": "application/json",
|
|
}
|
|
|
|
|
|
def main() -> None:
|
|
base = (os.environ.get("AZA_WOOCOMMERCE_URL") or "").strip().rstrip("/")
|
|
key = os.environ.get("AZA_WOOCOMMERCE_CONSUMER_KEY") or ""
|
|
sec = os.environ.get("AZA_WOOCOMMERCE_CONSUMER_SECRET") or ""
|
|
auth = HTTPBasicAuth(key, sec)
|
|
url = base + "/wp-json/wc/v3/subscriptions/1448"
|
|
r_bad = requests.get(url, auth=auth, timeout=15)
|
|
r_ok = requests.get(url, auth=auth, headers=BROWSER_HEADERS, timeout=15)
|
|
print("subscriptions_1448_default_requests_ua_http", r_bad.status_code)
|
|
print("subscriptions_1448_browserish_ua_http", r_ok.status_code)
|
|
if r_ok.headers.get("content-type", "").lower().startswith("application/json"):
|
|
try:
|
|
j = r_ok.json()
|
|
if isinstance(j, dict):
|
|
print("browserish_json_has_id", j.get("id") == 1448)
|
|
print("browserish_wp_error_code", j.get("code"))
|
|
except Exception:
|
|
print("browserish_json_parse", False)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|