본문 바로가기

Python

[python] REST API 호출 (requests 이용)

반응형

requests 이용 예시

1. requests install

docs.python-requests.org/en/latest/user/install/#install

python -m pip install requests

2. get

import requests

# GET
res = requests.get('url')
print(str(res.status_code) + " | " + res.text)

3. post

import requests
import json

# POST (JSON)
headers = {'Content-Type': 'application/json; chearset=utf-8'}
data = {'title': 'dummy title', 'id': 1, 'message': 'hello world!'}
res = requests.post('url', data=json.dumps(data), headers=headers)
print(str(res.status_code) + " | " + res.text)

 

docs.python-requests.org/en/latest/

 

Requests: HTTP for Humans™ — Requests 2.25.1 documentation

Requests: HTTP for Humans™ Release v2.25.1. (Installation) Requests is an elegant and simple HTTP library for Python, built for human beings. Behold, the power of Requests: >>> r = requests.get('https://api.github.com/user', auth=('user', 'pass')) >>> r.

docs.python-requests.org

my-devblog.tistory.com/27

 

[python] REST API 호출

REST API 호출 파이썬의 requests, urllib 모듈을 사용하여 REST API 호출하는 방법을 정리하였습니다. ※ requests는 Apache License 2.0의 라이센스를 가진 python HTTP 라이브러리 (requests 공식문서) ※ urll..

my-devblog.tistory.com

 

반응형