카카오 2차 코테 준비로 후다닥 정리해보았습니다.
https 통신
import requests
base_url = "base_url넣기"
def post_start(path, data):
headers = {
'Content-Type': 'application/json'
# ... 기타등등 헤더파일 반영
}
full_path = base_url + "/" + path
response = requests.post(full_path, headers=headers, data=data)
return response.text
def get_data(path, auth_key):
headers = {
# ... 기타등등 헤더파일 반영
'Content-Type': 'application/json'
}
full_path = base_url + "/" + path
response = requests.get(full_path, headers=headers)
return response.text
json 형식의 문자열 데이터를 Python객체로 읽기 - json.loads()
import json
json.loads(post_start("start",data_str))
cf ) Json 파일을 읽을 때에는 json.load()함수를 사용한다.
Python 객체를 json 문자열 타입으로 변환하기 - json.dumps()
json_str = json.dumps(cmd_dict) # 딕셔너리 타입을 json string 타입으로 변환
'개발일반 > Algorithms' 카테고리의 다른 글
삽입정렬(Insertion sort) 개념 이해하고 구현하기 (0) | 2021.11.02 |
---|---|
알고리즘스터디_5주차(210625 ~210701) 기록 (0) | 2021.07.04 |
Binary Search, Parametric Search 이해하기 (0) | 2021.07.03 |
댓글