Spaces:
Starting on A100
Starting on A100
File size: 2,224 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 | import os
import requests
def test_law():
oc = os.getenv("LAW_GO_KR_OC")
url = f"http://www.law.go.kr/DRF/lawSearch.do?target=law&query=๋ฏผ์&type=XML&OC={oc}"
try:
res = requests.get(url, timeout=10)
print(f"[LAW] Status: {res.status_code}")
if "์ฌ์ฉ์ ์ ๋ณด ๊ฒ์ฆ์ ์คํจ" in res.text:
print("[LAW] โ IP ๋ฏธ์น์ธ ์ํ (๋ฑ๋กํ IP๊ฐ ๋ฐ์๋์ง ์์๊ฑฐ๋ ๋ค๋ฆ)")
elif "<law" in res.text:
print("[LAW] โ
์ธ์ฆ ์ฑ๊ณต! ๋ฐ์ดํฐ ์์ง ๊ฐ๋ฅ")
else:
print(f"[LAW] โ ๏ธ ์๋ต ํ์ธ ํ์ (๋ด์ฉ ์ผ๋ถ): {res.text[:200]}")
except Exception as e:
print(f"[LAW] โ ์๋ฌ: {e}")
def test_alio():
key = os.getenv("DATA_GO_KR_API_KEY")
# Decoding ํค ์ฌ์ฉ
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)
print(f"[ALIO] Status: {res.status_code}")
if res.status_code == 200:
if "SERVICE_KEY_IS_NOT_REGISTERED" in res.text:
print("[ALIO] โ ํค ๋ฏธํ์ฑ ์ํ (๋๊ธฐํ ๋๊ธฐ ์ค)")
elif "INVALID_REQUEST_PARAMETER_ERROR" in res.text:
print("[ALIO] โ ํ๋ผ๋ฏธํฐ ์ค๋ฅ")
else:
try:
data = res.json()
# ๊ฒฐ๊ณผ ์ฝ๋ ํ์ธ
res_code = data.get("response", {}).get("header", {}).get("resultCode")
if res_code == "00":
print("[ALIO] โ
์ธ์ฆ ์ฑ๊ณต! ๋ฐ์ดํฐ ์์ง ๊ฐ๋ฅ")
else:
print(f"[ALIO] โ ๊ฒฐ๊ณผ ์ค๋ฅ (์ฝ๋: {res_code})")
except:
print(f"[ALIO] โ ๏ธ ๋น์ ์ ์๋ต (๋ด์ฉ ์ผ๋ถ): {res.text[:200]}")
else:
print(f"[ALIO] โ HTTP ์ค๋ฅ: {res.status_code}")
except Exception as e:
print(f"[ALIO] โ ์ฐ๊ฒฐ ์๋ฌ: {e}")
if __name__ == "__main__":
print("-" * 50)
print("๐ API ์ต์ข
์ ํจ์ฑ ๊ฒ์ฌ ์์")
test_law()
test_alio()
print("-" * 50)
|