Notice
Recent Posts
Recent Comments
Link
아미(아름다운미소)
python으로 REST API 호출 본문
python을 이용하여 간단한 REST client를 만들어 보겠습니다.
먼저 http request를 위해 사용할 라이브러리로 httplig2를 선택하였습니다.httplib2 : https://github.com/httplib2/httplib2
httplib2를 설치
$ pip install httplib2설치를 완료했으면 간단하게 테스트를 해보겠습니다.
아래의 코드를 작성하고 실행해 봅니다.
import httplib2 http = httplib2.Http() url = 'https://jsonplaceholder.typicode.com/posts/1' response, content = http.request(url, 'GET') print(content)아래와 같은 content가 나오면 성공^^.
b'{\n "userId": 1,\n "id": 1,\n "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",\n "body": "quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto"\n}'
'랭귀지 > python' 카테고리의 다른 글
[python] 파일, 디렉터리 조작 (0) | 2018.01.11 |
---|---|
[python] PyMySQL을 이용한 MySQL (0) | 2018.01.10 |
파이썬 이미지 처리(Pillow) (0) | 2018.01.03 |
[python] Flask WSGI 어플리케이션 (0) | 2017.12.29 |
[python] py2app을 통한 OS X용 실행파일 만들기 (0) | 2017.12.28 |
Comments