Spaces:
Paused
Paused
File size: 2,663 Bytes
769e684 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | 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)
|