#python #anaconda #jupyter-notebook #visual-code #html #css #javascript #http

제목naver api - datalab httperror 400: bad request2019-05-19 12:16
작성자

#using Naver api datalab
import os
import sys
import urllib.request


client_id = "_xP_qYjUj8ucgkurqtZe"
client_secret = "CStPyzBr_p"
url = "https://openapi.naver.com/v1/datalab/search";
body = "{"startDate":"2016-05-15","endDate":"2019-05-18","timeUnit":"month","keywordGroups":[{"groupName":"병 뒤집기","keywords":["물병","물병 뒤집기","병 뒤집기",]},{"groupName":"bottle flipping","keywords":["bottle flip","flipping bottle"]}],"device":"","ages":["",""],"gender":""}";

request = urllib.request.Request(url)
request.add_header("X-Naver-Client-Id",client_id)
request.add_header("X-Naver-Client-Secret",client_secret)
request.add_header("Content-Type","application/json")
response = urllib.request.urlopen(request, data=body.encode("utf-8"))
rescode = response.getcode()
if(rescode==200):
    response_body = response.read()
    print(response_body.decode('utf-8'))
else:
    print("Error Code:" + rescode)


위 프로그렘을 실행시키면 제목처럼

HTTPError 400:bad request 라는 에러가 뜨는데


문제는 NAVER Developers 에서 제공한 오류코드 해결 설명은(API 요청 URL의 프로토콜, 파라미터 등에 오류가 있는지 확인합니다.)  이렇게 되어있는데, 프로토콜, 파라미터 모두 (요청 url을 그냥 복붙 한거라...) 문제 없을 거라 생각했는데 오류가 났습니다.
어떤 부분이 문제인가요?

댓글
이전pygame 질문을 드려도 될까요?2019-05-19
다음텀프 주제 변경 질문2019-05-17