# OPEN API(공공데이터 포탈)

OPEN API ?

​

공공데이터를 이용하기 위해 공공 데이터 포털에 회원 가입합니다.&#x20;

{% embed url="<https://www.data.go.kr/​>" %}

![](/files/-LQm4maeT1NwdBWwk4uq)

![](/files/-LQm5GzVy1q9dItyY1ZZ)

![](/files/-LQm5I_upGB7T7v4ZpAL)

신청을 하고 난 후 **마이페이지**

![](/files/-LQm5U9wWze93RWidwNR)

![](/files/-LQm5X5T0POTXomT-8yT)

![](/files/-LQm5_oWBsQlrG1S6hpf)

테스트를 한 결과를 XML, JSON으로 받아봅시다.

{% code title="xml" %}

```
<OpenAPI_ServiceResponse>
	<cmmMsgHeader>
		<errMsg>SERVICE ERROR</errMsg>
		<returnAuthMsg>SERVICE_KEY_IS_NOT_REGISTERED_ERROR</returnAuthMsg>
		<returnReasonCode>30</returnReasonCode>
	</cmmMsgHeader>
</OpenAPI_ServiceResponse>
```

{% endcode %}

```
{"fields":[],"records":[]}
```

위와 같이 나온다면 서비스 키가 아직 등록되지 않은 상태이니 조금 기다려야 합니다.

정상적인 데이터는 아래와 같이 생겼습니다.

{% code title="공휴일 정보 조회.xml" %}

```
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<response>
    <header>
        <resultCode>00</resultCode>
        <resultMsg>NORMAL SERVICE.</resultMsg>
    </header>
    <body>
        <items>
            <item>
                <dateKind>01</dateKind>
                <dateName>어린이날</dateName>
                <isHoliday>Y</isHoliday>
                <locdate>20180505</locdate>
                <seq>1</seq>
            </item>
            <item>
                <dateKind>01</dateKind>
                <dateName>대체휴무일</dateName>
                <isHoliday>Y</isHoliday>
                <locdate>20180507</locdate>
                <seq>1</seq>
            </item>
            <item>
                <dateKind>01</dateKind>
                <dateName>부처님오신날</dateName>
                <isHoliday>Y</isHoliday>
                <locdate>20180522</locdate>
                <seq>1</seq>
            </item>
        </items>
        <numOfRows>10</numOfRows>
        <pageNo>1</pageNo>
        <totalCount>3</totalCount>
    </body>
</response>

```

{% endcode %}

{% code title="공휴일정보.json" %}

```
{"fields":
    [
        {"id":"dateKind"},
        {"id":"dateName"},
        {"id":"isHoliday"},
        {"id":"locdate"},
        {"id":"seq"}
    ],
    "records":[
        {
            "dateKind":"01",
            "locdate":"20180505",
            "seq":"1",
            "isHoliday":"Y",
            "dateName":"어린이날"
        },{
            "dateKind":"01",
            "locdate":"20180507",
            "seq":"1",
            "isHoliday":"Y",
            "dateName":"대체휴무일"
        },{
            "dateKind":"01",
            "locdate":"20180522",
            "seq":"1",
            "isHoliday":"Y",
            "dateName":"부처님오신날"
        }
    ]

}

```

{% endcode %}

XML보다 json이 데이터도 가볍고 사용 구조도 간단함으로 xml과 json을 둘다 제공한다면 json을 이용하는게 편합니다.\
여기서 json은 Python의 dictionary와 같은 구조를 가집니다.

&#x20;요청 api \
<http://apis.data.go.kr/B090041/openapi/service/SpcdeInfoService/getRestDeInfo?solYear=2018\\&solMonth=05\\&ServiceKey=발급받은> 일반 인증 키 &\_type=json xml, json&#x20;

구분은 젤 뒤 &\_type=xml , &\_type=json 두가지를 이용하면 된다.

2018년 05월의 공휴일은 \
20180505 어린이날, 20180507 대체휴무일, 20180522 부처님오신 날 3일 입니.

이처럼 공공데이터를 이용하면 다양한 정보를 쉽게 구할 수 있으니 필요한 정보가 있다면 한번 검색 해볼만합니.<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://study-code.gitbook.io/python-basic/open-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
