Spaces:
Paused
Paused
| import os | |
| import sys | |
| import requests | |
| def test_law_api(): | |
| oc = os.getenv("LAW_GO_KR_OC") | |
| url = "http://www.law.go.kr/DRF/lawSearch.do" | |
| params = {"target": "law", "query": "λ―Όμ", "type": "XML", "OC": oc} | |
| try: | |
| res = requests.get(url, params=params, timeout=10) | |
| if res.status_code == 200 and "<law" in res.text: | |
| print(f"[LAW API] β μ ν¨ν¨ (μνμ½λ: 200)") | |
| return True | |
| else: | |
| print(f"[LAW API] β μ€λ₯ (μνμ½λ: {res.status_code})") | |
| print(f"μλ΅λ΄μ© μΌλΆ: {res.text[:200]}") | |
| return False | |
| except Exception as e: | |
| print(f"[LAW API] β μ°κ²° μ€ν¨: {e}") | |
| return False | |
| def test_alio_api(): | |
| key = os.getenv("DATA_GO_KR_API_KEY") | |
| # Decoding ν€λ₯Ό μ¬μ©νκΈ° λλ¬Έμ requestsκ° ν λ² λ μΈμ½λ©νλλ‘ ν¨ | |
| url = "https://apis.data.go.kr/1051000/public_inst/list" | |
| params = {"serviceKey": key, "pageNo": 1, "numOfRows": 1, "resultType": "json"} | |
| try: | |
| res = requests.get(url, params=params, timeout=10) | |
| if res.status_code == 200: | |
| try: | |
| data = res.json() | |
| code = data.get("response", {}).get("header", {}).get("resultCode") | |
| if code == "00": | |
| print(f"[ALIO API] β μ ν¨ν¨ (μνμ½λ: 200, κ²°κ³Όμ½λ: 00)") | |
| return True | |
| else: | |
| msg = ( | |
| data.get("response", {}) | |
| .get("header", {}) | |
| .get("resultMsg", "μ μ μλ μ€λ₯") | |
| ) | |
| print(f"[ALIO API] β μΈμ¦ μ€λ₯ (κ²°κ³Όμ½λ: {code}, λ©μμ§: {msg})") | |
| return False | |
| except Exception: | |
| if "<ServiceKey Error" in res.text: | |
| print("[ALIO API] β μΈμ¦ν€ μ€λ₯ (ServiceKey Error)") | |
| else: | |
| print(f"[ALIO API] β λΉμ μ μλ΅: {res.text[:200]}") | |
| return False | |
| else: | |
| print(f"[ALIO API] β HTTP μ€λ₯ (μνμ½λ: {res.status_code})") | |
| return False | |
| except Exception as e: | |
| print(f"[ALIO API] β μ°κ²° μ€ν¨: {e}") | |
| return False | |
| if __name__ == "__main__": | |
| print("-" * 50) | |
| print("π API ν€ μ ν¨μ± κ²μ¬ μμ") | |
| law_ok = test_law_api() | |
| alio_ok = test_alio_api() | |
| print("-" * 50) | |
| if law_ok and alio_ok: | |
| print("β¨ λͺ¨λ API ν€κ° μ μμ μΌλ‘ μλν©λλ€!") | |
| else: | |
| print("β οΈ μΌλΆ API ν€μ νμΈμ΄ νμν©λλ€.") | |
| sys.exit(1) | |