Created
August 10, 2020 12:41
-
-
Save hwahyang1/8dda9e132aab627b1130bfa8c4bdaf47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import request, json | |
r = requests.post("https://siro.dev/api/urls") # https://siro.dev/api/urls에 POST로 요청을 보냅니다. | |
data = r.text # 응답값을 data에 저장합니다 HTTP 상태 코드를 원할 경우, r.status_code를 사용합니다. | |
data_loaded = json.loads(data) # 응답값이 JSON이기에, Python에서 사용할 수 있도록 변환 시켜줍니다. 그리고 data_loaded에 저장합니다. | |
# 이제 원하는 데이터를 data_loaded["데이터 이름"] 으로 가져올 수 있습니다! (List의 경우 문자열(따옴표) 대신 정수를 넣어 Index를 사용할 수 있습니다) | |
# Ex : data_loaded["api"]["date"] 로 "190806" 데이터를 가져 올 수 있습니다 (API 답변 상 {"api": {"date": "190806"}, (생략)} 의 구조임) | |
# ---------------------------------------------------------------- # | |
# 서버에 무언가 같이 첨부해야 할 데이터가 있으면 아래와 같이 작성합니다 | |
# SiroDev API의 스퀘어스크립트 암호화 API를 예제로 사용합니다. 자세한 내용은 API 문서를 참조하세요. | |
params = {'query': '암호화할내용'} # 서버에 보낼 데이터를 JSON 형식으로 작성합니다. | |
r = requests.post("https://siro.dev/api/sqc/encode", params=params) # 해당 URL에 지정한 헤더를 담아 전송합니다 | |
data = r.text | |
data_loaded = json.loads(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment