Notice
														
												
											
												
												
													Recent Posts
													
											
												
												
													Recent Comments
													
											
												
												
													Link
													
											
									| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 | 
| 12 | 13 | 14 | 15 | 16 | 17 | 18 | 
| 19 | 20 | 21 | 22 | 23 | 24 | 25 | 
| 26 | 27 | 28 | 29 | 30 | 31 | 
													Tags
													
											
												
												- PyQt5
- 유니티
- IOS
- pandas
- MySQL
- sqlite
- PyQt
- PER
- GIT
- Unity
- Linux
- python
- ubuntu
- javascript
- swift
- node.js
- Excel
- 날짜
- mssql
- MS-SQL
- port
- urllib
- 함수
- 라즈베리파이
- tensorflow
- 다이어트
- 맛집
- 리눅스
- ASP
- flutter
													Archives
													
											
											
											
											아미(아름다운미소)
json-rpc 1.10.8 본문
JSON-RPC2.0 및 JSON-RPC1.0 전송 사양 구현. 
            
                    
                            
         Python 2.6+, Python 3.3+, PyPy를 지원합니다. 
 Django와 Flask를 옵션으로 지원합니다. 
 Install
(pip로 간단하게 설치가 가능합니다.)
Quickstart 
이것은 JSON-RPC 표준에서 많은 경우가 있기 때문에 라이브러리의 필수 부분입니다. 
pip install json-rpc
선택적인 백엔드뿐만 아니라 다양한 지원되는 파이썬 버전을 관리하기 위해 json-rpc은 tox를 사용합니다
Server(uses Werkzeug)
Client (uses requests)
tox
from werkzeug.wrappers import Request, Response
from werkzeug.serving import run_simple
from jsonrpc import JSONRPCResponseManager, dispatcher
@dispatcher.add_method
def foobar(**kwargs):
    return kwargs["foo"] + kwargs["bar"]
@Request.application
def application(request):
    # Dispatcher is dictionary {: callable}
    dispatcher["echo"] = lambda s: s
    dispatcher["add"] = lambda a, b: a + b
    response = JSONRPCResponseManager.handle(
        request.data, dispatcher)
    return Response(response.json, mimetype='application/json')
if __name__ == '__main__':
    run_simple('localhost', 4000, application)
 import requests
import json
def main():
    url = "http://localhost:4000/jsonrpc"
    headers = {'content-type': 'application/json'}
    # Example echo method
    payload = {
        "method": "echo",
        "params": ["echome!"],
        "jsonrpc": "2.0",
        "id": 0,
    }
    response = requests.post(
        url, data=json.dumps(payload), headers=headers).json()
    assert response["result"] == "echome!"
    assert response["jsonrpc"]
    assert response["id"] == 0
if __name__ == "__main__":
    main()
'랭귀지 > python' 카테고리의 다른 글
| Python Django 우분투 설치 (0) | 2017.12.27 | 
|---|---|
| [python3.0] 웹 스크래핑(네이버 환율 정보) (0) | 2017.12.27 | 
| [PYTHON] 간단한 웹서버 구축하기 (0) | 2017.12.23 | 
| [python]사용자의 홈 디렉토리 경로 얻는 법 (0) | 2017.12.23 | 
| [BeautifulSoup]웹에서 정보 가져오기 (0) | 2017.12.22 | 
			  Comments