{"id":323,"date":"2018-08-09T17:50:31","date_gmt":"2018-08-09T08:50:31","guid":{"rendered":"http:\/\/dong1lkim.oboki.net\/?p=323"},"modified":"2019-09-01T22:21:34","modified_gmt":"2019-09-01T13:21:34","slug":"python-%ea%b3%b5%ea%b3%b5%eb%8d%b0%ec%9d%b4%ed%84%b0%ed%8f%ac%ed%84%b8-openapi-%ec%9d%b4%ec%9a%a9%ed%95%98%ea%b8%b0","status":"publish","type":"post","link":"https:\/\/oboki.net\/workspace\/python\/python-%ea%b3%b5%ea%b3%b5%eb%8d%b0%ec%9d%b4%ed%84%b0%ed%8f%ac%ed%84%b8-openapi-%ec%9d%b4%ec%9a%a9%ed%95%98%ea%b8%b0\/","title":{"rendered":"[Python] \uacf5\uacf5\ub370\uc774\ud130\ud3ec\ud138 openAPI \uc774\uc6a9\ud558\uae30"},"content":{"rendered":"<h1>\uacf5\uacf5\ub370\uc774\ud130\ud3ec\ud138 openAPI \uc774\uc6a9\ud558\uae30 Python<\/h1>\n<h2>\ud65c\uc6a9\uc2e0\uccad<\/h2>\n<ul>\n<li>\ud68c\uc6d0\uac00\uc785 \ud6c4 \uac1c\ubc1c\uacc4\uc815 \ubc1c\uae09 \uc2e0\uccad \ud544\uc694  <\/li>\n<li>\uc624\ud508API \uc81c\uacf5 \ub370\uc774\ud130\uc14b \uc120\ud0dd\n<ul>\n<li>\uc0ac\uc6a9 \ubaa9\uc801 \ub4f1 \uc2e0\uccad \uc0ac\uc720 \uc791\uc131\ud558\uc5ec \uc811\uc218. \uba87 \uc2dc\uac04 \uac78\ub9bc.<\/li>\n<\/ul>\n<\/li>\n<li>\uc77c\ubc18 \uc778\uc99d\ud0a4 \ubc1c\uae09\n<ul>\n<li>\ud0a4 \ubc1c\uae09 \uc2e0\uccad \uc774\ud6c4 \ud55c \uc2dc\uac04 \uc815\ub3c4 \uc9c0\ub098\uc57c \uc0ac\uc6a9 \ub418\ub294 \ub4ef.<\/li>\n<\/ul>\n<\/li>\n<li>\uac1c\ubc1c \uac00\uc774\ub4dc doc \ubcf4\uace0 \ub530\ub77c\ud558\uba74 \ub418\ub294\ub4ef<\/li>\n<\/ul>\n<h2>\ubcf4\ud589\uc790\ubb34\ub2e8\ud6a1\ub2e8\uc0ac\uace0\ub2e4\ubc1c\uc9c0\uc5ed\uc815\ubcf4 Rest \uc870\ud68c \uc608<\/h2>\n<h3>\uc544\ub798 URL\uc744 \uc6f9 \ube0c\ub77c\uc6b0\uc800\uc5d0\uc11c \uc870\ud68c<\/h3>\n<pre><code>http:\/\/apis.data.go.kr\/B552061\/jaywalking\/getRestJaywalking?serviceKey='YourServiceKey'&amp;searchYearCd=2015052&amp;siDo=11&amp;guGun=320\n<\/code><\/pre>\n<h3>\uc870\ud68c \uacb0\uacfc<\/h3>\n<pre><code>{\"searchResult\":{\"frequentzone\":[{\"fid\":6104257,\"grp_id\":\"2015052\",\"occcd\":\"1132010700\",\"spotcd\":\"113111001\",\"spot\":\"\uc11c\uc6b8 \uc11c\uc6b8\ub3c4\ubd091\",\"spotname\":\"\uc11c\uc6b8\ud2b9\ubcc4\uc2dc \ub3c4\ubd09\uad6c \ucc3d\ub3d9(\uc18c\ud53c\uc544\uad00\uad11\ud638\ud154 \ubd80\uadfc)\",\"occrrnc_co\":10,\"dthinj_co\":11,\"death_co\":0,\"serinj_co\":10,\"ordnr_co\":1,\"inj_co\":0,\"geometry\":\"{\\\"type\\\":\\\"Polygon\\\",\\\"coordinates\\\":[[[127.0377744,37.6515712],[127.0373687,37.6518466],[127.0369139,37.6520682],[127.036421,37.6522306],[127.0359023,37.6523296],[127.0353705,37.6523629],[127.0348387,37.6523296],[127.03432,37.6522306],[127.0338271,37.6520682],[127.0333723,37.6518466],[127.0329666,37.6515712],[127.0326202,37.6512486],[127.0323415,37.650887],[127.0321374,37.6504951],[127.0320129,37.6500827],[127.031971,37.6496599],[127.0320129,37.649237],[127.0321374,37.6488246],[127.0323416,37.6484328],[127.0326203,37.6480711],[127.0329668,37.6477486],[127.0333724,37.6474732],[127.0338272,37.6472516],[127.03432,37.6470892],[127.0348387,37.6469902],[127.0353705,37.646957],[127.0359023,37.6469902],[127.036421,37.6470892],[127.0369138,37.6472516],[127.0373686,37.6474732],[127.0377742,37.6477486],[127.0381207,37.6480711],[127.0383994,37.6484328],[127.0386036,37.6488246],[127.0387281,37.649237],[127.03877,37.6496599],[127.0387282,37.6500827],[127.0386036,37.6504951],[127.0383995,37.650887],[127.0381208,37.6512486],[127.0377744,37.6515712]]]}\",\"x_crd\":\"127.035370503247\",\"y_crd\":\"37.6496599073797\"}]},\"totalCount\":1,\"resultCode\":\"Success\"}\n<\/code><\/pre>\n<h3>Python\uc73c\ub85c \ub370\uc774\ud130 \uac00\uc838\uc624\uae30<\/h3>\n<h4>Source Code<\/h4>\n<pre><code>#!\/app\/python\/bin\/python\n\n# openapi_Jaywalking.py\n\nfrom urllib.request import urlopen\nfrom urllib.parse import urlencode,unquote,quote_plus\nimport urllib\n\nurl = 'http:\/\/apis.data.go.kr\/B552061\/jaywalking\/getRestJaywalking'\n\nqueryParams = '?' + urlencode({ quote_plus('servicekey') : 'YourServiceKey',\n    quote_plus('LAYERS') : 'frejaywalking',\n    quote_plus('FORMAT') : 'image\/png',\n    quote_plus('TRANSPARENT') : 'true',\n    quote_plus('SERVICE') : 'WMS',\n    quote_plus('VERSION') : '1.1.1',\n    quote_plus('REQUEST') : 'GetMap',\n    quote_plus('SRS') : 'EPSG:900913',\n    quote_plus('BBOX') : '14142684.718103,4505504.1936344,14147576.687913,4510396.1634438',\n    quote_plus('width') : '2024',\n    quote_plus('height') : '1838',\n    quote_plus('srs') : 'EPSG:900913',\n    quote_plus('searchYearCd') : '2015052',\n    quote_plus('siDo') : '11',\n    quote_plus('guGun') : '320' })\n\nrequest = urllib.request.Request(url+unquote(queryParams))\nprint ('Your Request:\\n'+url+queryParams)\nrequest.get_method = lambda: 'GET'\nresponse_body = urlopen(request).read()\nprint (\"\\nResult:\")\nprint (response_body)\nprint (\"\\nDataType of Result Data:\")\nprint (type(response_body))\n<\/code><\/pre>\n<h5>urllib.request<\/h5>\n<ul>\n<li>urlopen<\/li>\n<\/ul>\n<h5>urllib.parse<\/h5>\n<ul>\n<li>urlencode<\/li>\n<li>unquote<\/li>\n<li>quote_plus<\/li>\n<\/ul>\n<h4>Result<\/h4>\n<pre><code>Your Request:\nhttp:\/\/apis.data.go.kr\/B552061\/jaywalking\/getRestJaywalking?servicekey=YourServiceKey&searchYearCd=2015052&siDo=11&guGun=320\n\nResult:\nb'{\"searchResult\":{\"frequentzone\":[{\"fid\":6104257,\"grp_id\":\"2015052\",\"occcd\":\"1132010700\",\"spotcd\":\"113111001\",\"spot\":\"\\xec\\x84\\x9c\\xec\\x9a\\xb8 \\xec\\x84\\x9c\\xec\\x9a\\xb8\\xeb\\x8f\\x84\\xeb\\xb4\\x891\",\"spotname\":\"\\xec\\x84\\x9c\\xec\\x9a\\xb8\\xed\\x8a\\xb9\\xeb\\xb3\\x84\\xec\\x8b\\x9c \\xeb\\x8f\\x84\\xeb\\xb4\\x89\\xea\\xb5\\xac \\xec\\xb0\\xbd\\xeb\\x8f\\x99(\\xec\\x86\\x8c\\xed\\x94\\xbc\\xec\\x95\\x84\\xea\\xb4\\x80\\xea\\xb4\\x91\\xed\\x98\\xb8\\xed\\x85\\x94 \\xeb\\xb6\\x80\\xea\\xb7\\xbc)\",\"occrrnc_co\":10,\"dthinj_co\":11,\"death_co\":0,\"serinj_co\":10,\"ordnr_co\":1,\"inj_co\":0,\"geometry\":\"{\\\\\"type\\\\\":\\\\\"Polygon\\\\\",\\\\\"coordinates\\\\\":[[[127.0377744,37.6515712],[127.0373687,37.6518466],[127.0369139,37.6520682],[127.036421,37.6522306],[127.0359023,37.6523296],[127.0353705,37.6523629],[127.0348387,37.6523296],[127.03432,37.6522306],[127.0338271,37.6520682],[127.0333723,37.6518466],[127.0329666,37.6515712],[127.0326202,37.6512486],[127.0323415,37.650887],[127.0321374,37.6504951],[127.0320129,37.6500827],[127.031971,37.6496599],[127.0320129,37.649237],[127.0321374,37.6488246],[127.0323416,37.6484328],[127.0326203,37.6480711],[127.0329668,37.6477486],[127.0333724,37.6474732],[127.0338272,37.6472516],[127.03432,37.6470892],[127.0348387,37.6469902],[127.0353705,37.646957],[127.0359023,37.6469902],[127.036421,37.6470892],[127.0369138,37.6472516],[127.0373686,37.6474732],[127.0377742,37.6477486],[127.0381207,37.6480711],[127.0383994,37.6484328],[127.0386036,37.6488246],[127.0387281,37.649237],[127.03877,37.6496599],[127.0387282,37.6500827],[127.0386036,37.6504951],[127.0383995,37.650887],[127.0381208,37.6512486],[127.0377744,37.6515712]]]}\",\"x_crd\":\"127.035370503247\",\"y_crd\":\"37.6496599073797\"}]},\"totalCount\":1,\"resultCode\":\"Success\"}'\n\nDataType of Result Data:\n&lt;class 'bytes'&gt;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\uacf5\uacf5\ub370\uc774\ud130\ud3ec\ud138 openAPI \uc774\uc6a9\ud558\uae30 Python \ud65c\uc6a9\uc2e0\uccad \ud68c\uc6d0\uac00\uc785 \ud6c4 \uac1c\ubc1c\uacc4\uc815 \ubc1c\uae09 \uc2e0\uccad \ud544\uc694 \uc624\ud508API \uc81c\uacf5 \ub370\uc774\ud130\uc14b \uc120\ud0dd \uc0ac\uc6a9 \ubaa9\uc801 \ub4f1 \uc2e0\uccad \uc0ac\uc720 \uc791\uc131\ud558\uc5ec \uc811\uc218. \uba87 \uc2dc\uac04 \uac78\ub9bc. \uc77c\ubc18 \uc778\uc99d\ud0a4 \ubc1c\uae09 \ud0a4 \ubc1c\uae09 \uc2e0\uccad \uc774\ud6c4 \ud55c \uc2dc\uac04 \uc815\ub3c4 \uc9c0\ub098\uc57c \uc0ac\uc6a9 \ub418\ub294 \ub4ef. \uac1c\ubc1c \uac00\uc774\ub4dc doc \ubcf4\uace0 \ub530\ub77c\ud558\uba74 \ub418\ub294\ub4ef \ubcf4\ud589\uc790\ubb34\ub2e8\ud6a1\ub2e8\uc0ac\uace0\ub2e4\ubc1c\uc9c0\uc5ed\uc815\ubcf4 Rest \uc870\ud68c \uc608 \uc544\ub798 URL\uc744 \uc6f9 \ube0c\ub77c\uc6b0\uc800\uc5d0\uc11c \uc870\ud68c http:\/\/apis.data.go.kr\/B552061\/jaywalking\/getRestJaywalking?serviceKey=&#8217;YourServiceKey&#8217;&amp;searchYearCd=2015052&amp;siDo=11&amp;guGun=320 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[114],"class_list":["post-323","post","type-post","status-publish","format-standard","hentry","category-python","tag-openapi"],"_links":{"self":[{"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/posts\/323","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/comments?post=323"}],"version-history":[{"count":4,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/posts\/323\/revisions"}],"predecessor-version":[{"id":1254,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/posts\/323\/revisions\/1254"}],"wp:attachment":[{"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/media?parent=323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/categories?post=323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oboki.net\/workspace\/wp-json\/wp\/v2\/tags?post=323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}