Python responder v1.3.1 -> v1.3.2 변경, 추가 요약
그래서 저는 지난번 버전에서 이번 버전까지의 변경, 추가 기능을 총결하고 싶습니다.
responder란?여기 기사를 참고하세요.
→ 입문을 위해.. 사전 조사를
TL;DR
Release 메시지에네.
다음은 CHENGELOG의 관점입니다.
state
가 마핑 대상이 되었습니다ASGI3 지원
ASGI3는 starlette와responder 업데이트를 통해 지원됩니다.
이와 함께 ASGI2는 권장하지 않습니다.import responder
from logging import getLogger
from sentry_asgi import SentryMiddleware
import sentry_sdk
logger = getLogger(__name__)
sentry_sdk.init($URL)
api = responder.API()
api.add_middleware(SentryMiddleware)
@api.route("/")
def index(req, resp):
division_by_zero = 1 / 0
resp.text = ""
if __name__ == "__main__":
api.run(address="0.0.0.0", port=5000, debug=True)
INFO: Started server process [6]
INFO: Waiting for application startup.
INFO: Uvicorn running on http://0.0.0.0:5000 (Press CTRL+C to quit)
INFO: ('172.19.0.1', 44572) - "GET / HTTP/1.1" 500
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/uvicorn/protocols/http/httptools_impl.py", line 375, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "/usr/local/lib/python3.7/dist-packages/uvicorn/middleware/debug.py", line 81, in __call__
raise exc from None
File "/usr/local/lib/python3.7/dist-packages/uvicorn/middleware/debug.py", line 78, in __call__
await self.app(scope, receive, inner_send)
File "/usr/local/lib/python3.7/dist-packages/responder/api.py", line 277, in __call__
await self.app(scope, receive, send)
File "/usr/local/lib/python3.7/dist-packages/sentry_asgi/middleware.py", line 22, in __call__
raise exc from None
File "/usr/local/lib/python3.7/dist-packages/sentry_asgi/middleware.py", line 19, in __call__
await self.app(scope, receive, send)
File "/usr/local/lib/python3.7/dist-packages/starlette/middleware/errors.py", line 177, in __call__
raise exc from None
File "/usr/local/lib/python3.7/dist-packages/starlette/middleware/errors.py", line 155, in __call__
await self.app(scope, receive, _send)
File "/usr/local/lib/python3.7/dist-packages/starlette/middleware/trustedhost.py", line 34, in __call__
await self.app(scope, receive, send)
File "/usr/local/lib/python3.7/dist-packages/starlette/middleware/gzip.py", line 20, in __call__
await self.app(scope, receive, send)
File "/usr/local/lib/python3.7/dist-packages/responder/api.py", line 287, in asgi
req, scope=scope, send=send, receive=receive
File "/usr/local/lib/python3.7/dist-packages/responder/api.py", line 304, in _dispatch_http
await self._execute_route(route=route, req=req, resp=resp, **options)
File "/usr/local/lib/python3.7/dist-packages/responder/api.py", line 391, in _execute_route
await r
File "/usr/local/lib/python3.7/dist-packages/responder/background.py", line 44, in __call__
return await run_in_threadpool(func, *args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/starlette/concurrency.py", line 25, in run_in_threadpool
return await loop.run_in_executor(None, func, *args)
File "/usr/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "main.py", line 18, in index
division_by_zero = 1 / 0
ZeroDivisionError: division by zero
이렇게 하면 제3자의 중간부품을 가져올 수 있다.
자세한 내용은 확인하십시오Starlette Middleware.
파이썬 지원 버전 확장
pythn 3.7, 3.8-dev의 Citest가 추가되어 지원되었습니다.
request.state 속성
실체는starlette.requests.State
.import responder
import time
from logging import getLogger
logger = getLogger(__name__)
api = responder.API()
@api.route("/")
def index(req, resp):
logger.info(req.state)
logger.info(req.state._state)
req.state.time_started = time.time()
logger.info(req.state)
logger.info(req.state._state)
resp.text = f"{time.time() - req.state.time_started}"
if __name__ == "__main__":
api.run(address="0.0.0.0", port=5000, debug=True)
$ curl localhost:5000
0.0002288818359375$
INFO: Started server process [6]
INFO: Waiting for application startup.
INFO: Uvicorn running on http://0.0.0.0:5000 (Press CTRL+C to quit)
INFO: <starlette.requests.State object at 0x7fb61efc2240>
INFO: {}
INFO: <starlette.requests.State object at 0x7fb61efc2240>
INFO: {'time_started': 1566091621.639762}
INFO: ('172.19.0.1', 44320) - "GET / HTTP/1.1" 200
request.state
초기에는 아무것도 없었음을 확인할 수 있다.
이 request.state
에 변수 이름과 값을 저장할 수 있습니다.
middleware와의 대화에 사용할 수 있습니다.
on_event
starlette 옆api에 기대세요.on_이벤트의 이벤트는 startup과 shutdown 두 가지에만 대응하기 때문에 문서를 수정했습니다.(옛날부터인 것 같은데...)
기타 세부 변경 사항
Added
import responder
from logging import getLogger
from sentry_asgi import SentryMiddleware
import sentry_sdk
logger = getLogger(__name__)
sentry_sdk.init($URL)
api = responder.API()
api.add_middleware(SentryMiddleware)
@api.route("/")
def index(req, resp):
division_by_zero = 1 / 0
resp.text = ""
if __name__ == "__main__":
api.run(address="0.0.0.0", port=5000, debug=True)
INFO: Started server process [6]
INFO: Waiting for application startup.
INFO: Uvicorn running on http://0.0.0.0:5000 (Press CTRL+C to quit)
INFO: ('172.19.0.1', 44572) - "GET / HTTP/1.1" 500
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/uvicorn/protocols/http/httptools_impl.py", line 375, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "/usr/local/lib/python3.7/dist-packages/uvicorn/middleware/debug.py", line 81, in __call__
raise exc from None
File "/usr/local/lib/python3.7/dist-packages/uvicorn/middleware/debug.py", line 78, in __call__
await self.app(scope, receive, inner_send)
File "/usr/local/lib/python3.7/dist-packages/responder/api.py", line 277, in __call__
await self.app(scope, receive, send)
File "/usr/local/lib/python3.7/dist-packages/sentry_asgi/middleware.py", line 22, in __call__
raise exc from None
File "/usr/local/lib/python3.7/dist-packages/sentry_asgi/middleware.py", line 19, in __call__
await self.app(scope, receive, send)
File "/usr/local/lib/python3.7/dist-packages/starlette/middleware/errors.py", line 177, in __call__
raise exc from None
File "/usr/local/lib/python3.7/dist-packages/starlette/middleware/errors.py", line 155, in __call__
await self.app(scope, receive, _send)
File "/usr/local/lib/python3.7/dist-packages/starlette/middleware/trustedhost.py", line 34, in __call__
await self.app(scope, receive, send)
File "/usr/local/lib/python3.7/dist-packages/starlette/middleware/gzip.py", line 20, in __call__
await self.app(scope, receive, send)
File "/usr/local/lib/python3.7/dist-packages/responder/api.py", line 287, in asgi
req, scope=scope, send=send, receive=receive
File "/usr/local/lib/python3.7/dist-packages/responder/api.py", line 304, in _dispatch_http
await self._execute_route(route=route, req=req, resp=resp, **options)
File "/usr/local/lib/python3.7/dist-packages/responder/api.py", line 391, in _execute_route
await r
File "/usr/local/lib/python3.7/dist-packages/responder/background.py", line 44, in __call__
return await run_in_threadpool(func, *args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/starlette/concurrency.py", line 25, in run_in_threadpool
return await loop.run_in_executor(None, func, *args)
File "/usr/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "main.py", line 18, in index
division_by_zero = 1 / 0
ZeroDivisionError: division by zero
pythn 3.7, 3.8-dev의 Citest가 추가되어 지원되었습니다.
request.state 속성
실체는starlette.requests.State
.import responder
import time
from logging import getLogger
logger = getLogger(__name__)
api = responder.API()
@api.route("/")
def index(req, resp):
logger.info(req.state)
logger.info(req.state._state)
req.state.time_started = time.time()
logger.info(req.state)
logger.info(req.state._state)
resp.text = f"{time.time() - req.state.time_started}"
if __name__ == "__main__":
api.run(address="0.0.0.0", port=5000, debug=True)
$ curl localhost:5000
0.0002288818359375$
INFO: Started server process [6]
INFO: Waiting for application startup.
INFO: Uvicorn running on http://0.0.0.0:5000 (Press CTRL+C to quit)
INFO: <starlette.requests.State object at 0x7fb61efc2240>
INFO: {}
INFO: <starlette.requests.State object at 0x7fb61efc2240>
INFO: {'time_started': 1566091621.639762}
INFO: ('172.19.0.1', 44320) - "GET / HTTP/1.1" 200
request.state
초기에는 아무것도 없었음을 확인할 수 있다.
이 request.state
에 변수 이름과 값을 저장할 수 있습니다.
middleware와의 대화에 사용할 수 있습니다.
on_event
starlette 옆api에 기대세요.on_이벤트의 이벤트는 startup과 shutdown 두 가지에만 대응하기 때문에 문서를 수정했습니다.(옛날부터인 것 같은데...)
기타 세부 변경 사항
Added
import responder
import time
from logging import getLogger
logger = getLogger(__name__)
api = responder.API()
@api.route("/")
def index(req, resp):
logger.info(req.state)
logger.info(req.state._state)
req.state.time_started = time.time()
logger.info(req.state)
logger.info(req.state._state)
resp.text = f"{time.time() - req.state.time_started}"
if __name__ == "__main__":
api.run(address="0.0.0.0", port=5000, debug=True)
$ curl localhost:5000
0.0002288818359375$
INFO: Started server process [6]
INFO: Waiting for application startup.
INFO: Uvicorn running on http://0.0.0.0:5000 (Press CTRL+C to quit)
INFO: <starlette.requests.State object at 0x7fb61efc2240>
INFO: {}
INFO: <starlette.requests.State object at 0x7fb61efc2240>
INFO: {'time_started': 1566091621.639762}
INFO: ('172.19.0.1', 44320) - "GET / HTTP/1.1" 200
starlette 옆api에 기대세요.on_이벤트의 이벤트는 startup과 shutdown 두 가지에만 대응하기 때문에 문서를 수정했습니다.(옛날부터인 것 같은데...)
기타 세부 변경 사항
Added
multipart/form-data
의 파일 이외의 데이터와 대응Rename
Remove
라이브러리 주위에 의존
제출 로그 목록
참고 자료
Reference
이 문제에 관하여(Python responder v1.3.1 -> v1.3.2 변경, 추가 요약), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/y_k/items/a83519798244e83faf38텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)