{"id":17057,"date":"2025-04-18T23:31:46","date_gmt":"2025-04-18T15:31:46","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/17057.html"},"modified":"2025-04-18T23:31:46","modified_gmt":"2025-04-18T15:31:46","slug":"python-uvicorn%e5%ba%93%ef%bc%9a%e4%b8%80%e6%ac%be%e9%ab%98%e6%80%a7%e8%83%bd%e7%9a%84asgi%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/17057.html","title":{"rendered":"Python uvicorn\u5e93\uff1a\u4e00\u6b3e\u9ad8\u6027\u80fd\u7684ASGI\u670d\u52a1\u5668"},"content":{"rendered":"<p style=\"text-align:left\"><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418153145-680270614c518.png\" alt=\"e83d9802a42649c35620d9dc1a9153d3.png\" \/><\/p>\n<p style=\"text-align:left\">\u66f4\u591aPython\u5b66\u4e60\u5185\u5bb9&#xff1a;ipengtao.com<\/p>\n<p>\u5728\u6784\u5efa\u73b0\u4ee3Web\u5e94\u7528\u7a0b\u5e8f\u65f6&#xff0c;\u6027\u80fd\u548c\u5e76\u53d1\u80fd\u529b\u662f\u91cd\u8981\u7684\u8003\u91cf\u56e0\u7d20\u3002\u4f20\u7edf\u7684WSGI\u670d\u52a1\u5668\u5df2\u65e0\u6cd5\u6ee1\u8db3\u5f02\u6b65Web\u6846\u67b6\u7684\u9700\u6c42&#xff0c;\u800cASGI&#xff08;Asynchronous Server Gateway Interface&#xff09;\u6210\u4e3a\u65b0\u4e00\u4ee3Web\u670d\u52a1\u5668\u63a5\u53e3\u7684\u6807\u51c6\u3002Uvicorn \u662f\u4e00\u4e2a\u5feb\u901f\u3001\u8f7b\u91cf\u7ea7\u7684ASGI\u670d\u52a1\u5668&#xff0c;\u652f\u6301\u5f02\u6b65Web\u6846\u67b6&#xff08;\u5982FastAPI\u548cStarlette&#xff09;\u4ee5\u53caHTTP\/2\u548cWebSocket\u3002Uvicorn \u57fa\u4e8e uvloop \u548c httptools \u6784\u5efa&#xff0c;\u5177\u6709\u9ad8\u6027\u80fd\u3001\u6613\u7528\u6027\u548c\u7075\u6d3b\u6027\u7684\u7279\u70b9\u3002<\/p>\n<h3>\u5b89\u88c5<\/h3>\n<p>\u8981\u5f00\u59cb\u4f7f\u7528 Uvicorn&#xff0c;\u9996\u5148\u9700\u8981\u5b89\u88c5\u5b83\u3002<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7 pip \u5b89\u88c5&#xff1a;<\/p>\n<p> pip\u00a0install\u00a0uvicorn <\/p>\n<p>\u4e3a\u4e86\u83b7\u5f97\u6700\u4f73\u6027\u80fd&#xff0c;\u53ef\u4ee5\u5b89\u88c5\u5e26Cython\u4f18\u5316\u7684\u7248\u672c&#xff1a;<\/p>\n<p> pip\u00a0install\u00a0&#034;uvicorn[standard]&#034; <\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e&#xff0c;\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f&#xff1a;<\/p>\n<p> uvicorn\u00a0&#8211;version <\/p>\n<h3>\u4e3b\u8981\u529f\u80fd<\/h3>\n<ul>\n<li>\n<p>\u652f\u6301ASGI\u534f\u8bae&#xff1a;\u5b8c\u5168\u517c\u5bb9ASGI\u6807\u51c6&#xff0c;\u53ef\u4ee5\u8fd0\u884c\u5f02\u6b65\u548c\u540c\u6b65\u7684Web\u5e94\u7528\u3002<\/p>\n<\/li>\n<li>\n<p>\u9ad8\u6027\u80fd&#xff1a;\u57fa\u4e8e uvloop \u548c httptools&#xff0c;\u652f\u6301\u9ad8\u541e\u5410\u91cf\u548c\u4f4e\u5ef6\u8fdf\u3002<\/p>\n<\/li>\n<li>\n<p>\u652f\u6301HTTP\/2\u548cWebSocket&#xff1a;\u6ee1\u8db3\u73b0\u4ee3Web\u5e94\u7528\u7684\u5b9e\u65f6\u901a\u4fe1\u9700\u6c42\u3002<\/p>\n<\/li>\n<li>\n<p>\u70ed\u91cd\u8f7d&#xff1a;\u5f00\u53d1\u6a21\u5f0f\u4e0b\u652f\u6301\u4ee3\u7801\u70ed\u91cd\u8f7d&#xff0c;\u63d0\u5347\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<\/li>\n<li>\n<p>\u7075\u6d3b\u7684\u914d\u7f6e&#xff1a;\u901a\u8fc7\u547d\u4ee4\u884c\u53c2\u6570\u6216Python\u4ee3\u7801\u81ea\u5b9a\u4e49\u8fd0\u884c\u9009\u9879\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8fd9\u4e9b\u529f\u80fd\u4f7f Uvicorn \u6210\u4e3a\u6784\u5efa\u9ad8\u6027\u80fdWeb\u5e94\u7528\u7684\u7406\u60f3\u9009\u62e9\u3002<\/p>\n<h3>\u57fa\u7840\u7528\u6cd5<\/h3>\n<h4>\u8fd0\u884c\u7b80\u5355\u7684ASGI\u5e94\u7528<\/h4>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u6700\u7b80\u5355\u7684ASGI\u5e94\u7528\u793a\u4f8b&#xff1a;<\/p>\n<p> async\u00a0def\u00a0app(scope,\u00a0receive,\u00a0send):<br \/>\n\u00a0\u00a0\u00a0\u00a0assert\u00a0scope[&#039;type&#039;]\u00a0&#061;&#061;\u00a0&#039;http&#039;<br \/>\n\u00a0\u00a0\u00a0\u00a0response\u00a0&#061;\u00a0b&#034;Hello,\u00a0Uvicorn!&#034;<br \/>\n\u00a0\u00a0\u00a0\u00a0await\u00a0send({<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#039;type&#039;:\u00a0&#039;http.response.start&#039;,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#039;status&#039;:\u00a0200,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#039;headers&#039;:\u00a0[(b&#039;content-type&#039;,\u00a0b&#039;text\/plain&#039;)],<br \/>\n\u00a0\u00a0\u00a0\u00a0})<br \/>\n\u00a0\u00a0\u00a0\u00a0await\u00a0send({<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#039;type&#039;:\u00a0&#039;http.response.body&#039;,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#039;body&#039;:\u00a0response,<br \/>\n\u00a0\u00a0\u00a0\u00a0}) <\/p>\n<p>\u4f7f\u7528 Uvicorn \u8fd0\u884c\u8be5\u5e94\u7528&#xff1a;<\/p>\n<p> uvicorn\u00a0app:app\u00a0&#8211;host\u00a0127.0.0.1\u00a0&#8211;port\u00a08000 <\/p>\n<p>\u6253\u5f00\u6d4f\u89c8\u5668\u8bbf\u95ee http:\/\/127.0.0.1:8000&#xff0c;\u5c06\u663e\u793a \u201cHello, Uvicorn!\u201d\u3002<\/p>\n<h4>\u96c6\u6210\u5f02\u6b65Web\u6846\u67b6<\/h4>\n<p>Uvicorn \u5e38\u4e0e\u5f02\u6b65Web\u6846\u67b6&#xff08;\u5982FastAPI&#xff09;\u4e00\u8d77\u4f7f\u7528\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u96c6\u6210FastAPI\u7684\u793a\u4f8b&#xff1a;<\/p>\n<p> from\u00a0fastapi\u00a0import\u00a0FastAPI<\/p>\n<p>app\u00a0&#061;\u00a0FastAPI()<\/p>\n<p>&#064;app.get(&#034;\/&#034;)<br \/>\nasync\u00a0def\u00a0read_root():<br \/>\n\u00a0\u00a0\u00a0\u00a0return\u00a0{&#034;message&#034;:\u00a0&#034;Welcome\u00a0to\u00a0Uvicorn\u00a0with\u00a0FastAPI!&#034;} <\/p>\n<p>\u8fd0\u884c\u8be5\u5e94\u7528&#xff1a;<\/p>\n<p> uvicorn\u00a0main:app\u00a0&#8211;reload <\/p>\n<p>&#8211;reload \u53c2\u6570\u542f\u7528\u4ee3\u7801\u70ed\u91cd\u8f7d\u529f\u80fd&#xff0c;\u6bcf\u6b21\u4fee\u6539\u4ee3\u7801\u540e\u670d\u52a1\u5668\u5c06\u81ea\u52a8\u91cd\u542f\u3002<\/p>\n<h4>\u81ea\u5b9a\u4e49\u8fd0\u884c\u53c2\u6570<\/h4>\n<p>Uvicorn \u652f\u6301\u901a\u8fc7\u547d\u4ee4\u884c\u6216Python\u4ee3\u7801\u81ea\u5b9a\u4e49\u8fd0\u884c\u53c2\u6570\u3002<\/p>\n<p>\u4f8b\u5982&#xff0c;\u53ef\u4ee5\u542f\u7528HTTP\/2\u652f\u6301\u6216\u8bbe\u7f6e\u5de5\u4f5c\u7ebf\u7a0b\u6570&#xff1a;<\/p>\n<p> uvicorn\u00a0main:app\u00a0&#8211;host\u00a00.0.0.0\u00a0&#8211;port\u00a08080\u00a0&#8211;http\u00a0h11\u00a0&#8211;workers\u00a04 <\/p>\n<p>\u4e5f\u53ef\u4ee5\u901a\u8fc7Python\u811a\u672c\u8fd0\u884c&#xff1a;<\/p>\n<p> import\u00a0uvicorn<\/p>\n<p>if\u00a0__name__\u00a0&#061;&#061;\u00a0&#034;__main__&#034;:<br \/>\n\u00a0\u00a0\u00a0\u00a0uvicorn.run(&#034;main:app&#034;,\u00a0host&#061;&#034;0.0.0.0&#034;,\u00a0port&#061;8080,\u00a0workers&#061;4) <\/p>\n<h3>\u8fdb\u9636\u7528\u6cd5<\/h3>\n<h4>\u65e5\u5fd7\u914d\u7f6e<\/h4>\n<p>Uvicorn \u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u65e5\u5fd7\u914d\u7f6e\u9009\u9879&#xff0c;\u53ef\u4ee5\u901a\u8fc7 &#8211;log-level \u53c2\u6570\u8bbe\u7f6e\u65e5\u5fd7\u7ea7\u522b&#xff1a;<\/p>\n<p> uvicorn\u00a0main:app\u00a0&#8211;log-level\u00a0debug <\/p>\n<p>\u5982\u679c\u9700\u8981\u81ea\u5b9a\u4e49\u65e5\u5fd7\u683c\u5f0f&#xff0c;\u53ef\u4ee5\u5728Python\u811a\u672c\u4e2d\u914d\u7f6e&#xff1a;<\/p>\n<p> import\u00a0logging<br \/>\nimport\u00a0uvicorn<\/p>\n<p>if\u00a0__name__\u00a0&#061;&#061;\u00a0&#034;__main__&#034;:<br \/>\n\u00a0\u00a0\u00a0\u00a0logging.basicConfig(level&#061;logging.INFO,\u00a0format&#061;&#034;%(asctime)s\u00a0&#8211;\u00a0%(message)s&#034;)<br \/>\n\u00a0\u00a0\u00a0\u00a0uvicorn.run(&#034;main:app&#034;,\u00a0log_level&#061;&#034;info&#034;) <\/p>\n<h4>\u542f\u7528SSL\u652f\u6301<\/h4>\n<p>Uvicorn \u652f\u6301HTTPS&#xff0c;\u901a\u8fc7\u6307\u5b9aSSL\u8bc1\u4e66\u548c\u79c1\u94a5\u5373\u53ef\u542f\u7528&#xff1a;<\/p>\n<p> uvicorn\u00a0main:app\u00a0&#8211;ssl-keyfile\u00a0key.pem\u00a0&#8211;ssl-certfile\u00a0cert.pem <\/p>\n<p>\u8fd9\u5728\u9700\u8981\u4fdd\u62a4\u654f\u611f\u6570\u636e\u7684\u573a\u666f\u4e2d\u975e\u5e38\u6709\u7528\u3002<\/p>\n<h4>\u4f7f\u7528\u81ea\u5b9a\u4e49\u4e2d\u95f4\u4ef6<\/h4>\n<p>Uvicorn \u652f\u6301\u81ea\u5b9a\u4e49\u4e2d\u95f4\u4ef6\u6765\u6269\u5c55ASGI\u5e94\u7528\u7684\u529f\u80fd\u3002<\/p>\n<p>\u4f8b\u5982&#xff0c;\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u65e5\u5fd7\u4e2d\u95f4\u4ef6&#xff1a;<\/p>\n<p> class\u00a0LogMiddleware:<br \/>\n\u00a0\u00a0\u00a0\u00a0def\u00a0__init__(self,\u00a0app):<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0self.app\u00a0&#061;\u00a0app<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0async\u00a0def\u00a0__call__(self,\u00a0scope,\u00a0receive,\u00a0send):<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0print(f&#034;New\u00a0request:\u00a0{scope[&#039;path&#039;]}&#034;)<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0await\u00a0self.app(scope,\u00a0receive,\u00a0send)<\/p>\n<p>async\u00a0def\u00a0app(scope,\u00a0receive,\u00a0send):<br \/>\n\u00a0\u00a0\u00a0\u00a0assert\u00a0scope[&#039;type&#039;]\u00a0&#061;&#061;\u00a0&#039;http&#039;<br \/>\n\u00a0\u00a0\u00a0\u00a0response\u00a0&#061;\u00a0b&#034;Hello,\u00a0Middleware!&#034;<br \/>\n\u00a0\u00a0\u00a0\u00a0await\u00a0send({<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#039;type&#039;:\u00a0&#039;http.response.start&#039;,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#039;status&#039;:\u00a0200,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#039;headers&#039;:\u00a0[(b&#039;content-type&#039;,\u00a0b&#039;text\/plain&#039;)],<br \/>\n\u00a0\u00a0\u00a0\u00a0})<br \/>\n\u00a0\u00a0\u00a0\u00a0await\u00a0send({<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#039;type&#039;:\u00a0&#039;http.response.body&#039;,<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#039;body&#039;:\u00a0response,<br \/>\n\u00a0\u00a0\u00a0\u00a0})<\/p>\n<p>app\u00a0&#061;\u00a0LogMiddleware(app) <\/p>\n<p>\u8fd0\u884c\u4e0a\u8ff0\u4ee3\u7801\u540e&#xff0c;\u670d\u52a1\u5668\u5c06\u8bb0\u5f55\u6bcf\u4e2a\u8bf7\u6c42\u7684\u8def\u5f84\u3002<\/p>\n<h4>\u591a\u8fdb\u7a0b\u6a21\u5f0f<\/h4>\n<p>\u5728\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b&#xff0c;\u53ef\u4ee5\u901a\u8fc7 &#8211;workers \u53c2\u6570\u542f\u7528\u591a\u8fdb\u7a0b\u6a21\u5f0f&#xff0c;\u4ee5\u63d0\u5347\u6027\u80fd&#xff1a;<\/p>\n<p> uvicorn\u00a0main:app\u00a0&#8211;workers\u00a04 <\/p>\n<p>\u6bcf\u4e2a\u8fdb\u7a0b\u5c06\u72ec\u7acb\u5904\u7406\u8bf7\u6c42&#xff0c;\u6709\u52a9\u4e8e\u5145\u5206\u5229\u7528\u591a\u6838CPU\u3002<\/p>\n<h3>\u5b9e\u9645\u5e94\u7528<\/h3>\n<h4>\u6784\u5efa\u5b9e\u65f6\u804a\u5929\u5e94\u7528<\/h4>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684WebSocket\u804a\u5929\u5e94\u7528&#xff1a;<\/p>\n<p> from\u00a0fastapi\u00a0import\u00a0FastAPI,\u00a0WebSocket<\/p>\n<p>app\u00a0&#061;\u00a0FastAPI()<\/p>\n<p>&#064;app.websocket(&#034;\/chat&#034;)<br \/>\nasync\u00a0def\u00a0chat(websocket:\u00a0WebSocket):<br \/>\n\u00a0\u00a0\u00a0\u00a0await\u00a0websocket.accept()<br \/>\n\u00a0\u00a0\u00a0\u00a0while\u00a0True:<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0data\u00a0&#061;\u00a0await\u00a0websocket.receive_text()<br \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0await\u00a0websocket.send_text(f&#034;Message\u00a0received:\u00a0{data}&#034;) <\/p>\n<p>\u8fd0\u884c\u8be5\u5e94\u7528\u5e76\u4f7f\u7528WebSocket\u5ba2\u6237\u7aef\u6d4b\u8bd5&#xff0c;\u5373\u53ef\u5b9e\u73b0\u5b9e\u65f6\u6d88\u606f\u4ea4\u4e92\u3002<\/p>\n<h4>\u5f00\u53d1\u9ad8\u6027\u80fdAPI\u670d\u52a1<\/h4>\n<p>\u901a\u8fc7 Uvicorn \u548c FastAPI&#xff0c;\u53ef\u4ee5\u5feb\u901f\u6784\u5efa\u4e00\u4e2a\u9ad8\u6027\u80fd\u7684RESTful API&#xff1a;<\/p>\n<p> from\u00a0fastapi\u00a0import\u00a0FastAPI<\/p>\n<p>app\u00a0&#061;\u00a0FastAPI()<\/p>\n<p>&#064;app.get(&#034;\/items\/{item_id}&#034;)<br \/>\nasync\u00a0def\u00a0read_item(item_id:\u00a0int,\u00a0q:\u00a0str\u00a0&#061;\u00a0None):<br \/>\n\u00a0\u00a0\u00a0\u00a0return\u00a0{&#034;item_id&#034;:\u00a0item_id,\u00a0&#034;q&#034;:\u00a0q} <\/p>\n<p>\u8fd0\u884c\u540e\u53ef\u4ee5\u901a\u8fc7 curl \u6216\u5176\u4ed6\u5de5\u5177\u6d4b\u8bd5&#xff1a;<\/p>\n<p> curl\u00a0&#034;http:\/\/127.0.0.1:8000\/items\/42?q&#061;test&#034; <\/p>\n<p>\u8fd4\u56de\u7ed3\u679c&#xff1a;<\/p>\n<p> {<br \/>\n\u00a0\u00a0&#034;item_id&#034;:\u00a042,<br \/>\n\u00a0\u00a0&#034;q&#034;:\u00a0&#034;test&#034;<br \/>\n} <\/p>\n<h4>\u90e8\u7f72\u673a\u5668\u5b66\u4e60\u6a21\u578b<\/h4>\n<p>Uvicorn \u5e38\u7528\u4e8e\u90e8\u7f72\u673a\u5668\u5b66\u4e60\u6a21\u578b\u3002<\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u5c06\u4e00\u4e2a\u9884\u8bad\u7ec3\u7684\u6a21\u578b\u66b4\u9732\u4e3aAPI&#xff1a;<\/p>\n<p> from\u00a0fastapi\u00a0import\u00a0FastAPI<br \/>\nimport\u00a0joblib<\/p>\n<p>app\u00a0&#061;\u00a0FastAPI()<br \/>\nmodel\u00a0&#061;\u00a0joblib.load(&#034;model.pkl&#034;)<\/p>\n<p>&#064;app.post(&#034;\/predict&#034;)<br \/>\nasync\u00a0def\u00a0predict(features:\u00a0dict):<br \/>\n\u00a0\u00a0\u00a0\u00a0prediction\u00a0&#061;\u00a0model.predict([list(features.values())])<br \/>\n\u00a0\u00a0\u00a0\u00a0return\u00a0{&#034;prediction&#034;:\u00a0prediction[0]} <\/p>\n<p>\u901a\u8fc7 Uvicorn \u8fd0\u884c\u8be5\u670d\u52a1&#xff0c;\u5373\u53ef\u5c06\u673a\u5668\u5b66\u4e60\u6a21\u578b\u96c6\u6210\u5230\u5e94\u7528\u4e2d\u3002<\/p>\n<h3>\u603b\u7ed3<\/h3>\n<p>Uvicorn \u662f\u4e00\u4e2a\u9ad8\u6027\u80fd\u7684ASGI\u670d\u52a1\u5668&#xff0c;\u4e13\u4e3a\u652f\u6301\u73b0\u4ee3\u5f02\u6b65Web\u6846\u67b6\u800c\u8bbe\u8ba1&#xff0c;\u5982FastAPI\u548cStarlette\u3002\u5b83\u57fa\u4e8e uvloop \u548c httptools&#xff0c;\u5177\u6709\u5feb\u901f\u54cd\u5e94\u3001\u9ad8\u5e76\u53d1\u5904\u7406\u80fd\u529b\u4ee5\u53ca\u5bf9HTTP\/2\u548cWebSocket\u7684\u539f\u751f\u652f\u6301\u3002\u4f5c\u4e3a\u8f7b\u91cf\u7ea7\u670d\u52a1\u5668&#xff0c;Uvicorn \u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u914d\u7f6e\u9009\u9879&#xff0c;\u5305\u62ec\u591a\u8fdb\u7a0b\u6a21\u5f0f\u3001SSL\u652f\u6301\u548c\u81ea\u5b9a\u4e49\u65e5\u5fd7\u914d\u7f6e\u7b49&#xff0c;\u540c\u65f6\u652f\u6301\u4ee3\u7801\u70ed\u91cd\u8f7d&#xff0c;\u5927\u5927\u63d0\u9ad8\u4e86\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<p>\u5982\u679c\u4f60\u89c9\u5f97\u6587\u7ae0\u8fd8\u4e0d\u9519&#xff0c;\u8bf7\u5927\u5bb6 \u70b9\u8d5e\u3001\u5206\u4eab\u3001\u7559\u8a00 \u4e0b&#xff0c;\u56e0\u4e3a\u8fd9\u5c06\u662f\u6211\u6301\u7eed\u8f93\u51fa\u66f4\u591a\u4f18\u8d28\u6587\u7ae0\u7684\u6700\u5f3a\u52a8\u529b&#xff01;<\/p>\n<hr \/>\n<p>\u6211\u4eec\u8fd8\u4e3a\u5927\u5bb6\u51c6\u5907\u4e86Python\u8d44\u6599&#xff0c;\u611f\u5174\u8da3\u7684\u5c0f\u4f19\u4f34\u5feb\u6765\u627e\u6211\u9886\u53d6\u4e00\u8d77\u4ea4\u6d41\u5b66\u4e60\u54e6&#xff01;<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418153145-6802706174b01.png\" alt=\"63a82ea4d9dd466bdc15f241649ee644.jpeg\" \/><\/p>\n<p>\u5f80\u671f\u63a8\u8350<\/p>\n<\/p>\n<p>Python\u57fa\u7840\u5b66\u4e60\u5e38\u89c1\u7684100\u4e2a\u95ee\u9898.pdf&#xff08;\u9644\u7b54\u6848&#xff09;<\/p>\n<\/p>\n<p>Python\u529e\u516c\u81ea\u52a8\u5316\u5b8c\u5168\u6307\u5357(\u514d\u8d39PDF)<\/p>\n<\/p>\n<p>Python Web \u5f00\u53d1\u5e38\u89c1\u7684100\u4e2a\u95ee\u9898.PDF<\/p>\n<\/p>\n<p>Beautiful Soup\u5feb\u901f\u4e0a\u624b\u6307\u5357&#xff0c;\u4ece\u5165\u95e8\u5230\u7cbe\u901a(PDF\u4e0b\u8f7d)<\/p>\n<\/p>\n<p>124\u4e2aPython\u6848\u4f8b&#xff0c;\u5b8c\u6574\u6e90\u4ee3\u7801&#xff01;<\/p>\n<\/p>\n<p>80\u4e2aPython\u6570\u636e\u5206\u6790\u5fc5\u5907\u5b9e\u6218\u6848\u4f8b.pdf(\u9644\u4ee3\u7801)&#xff0c;\u5b8c\u5168\u5f00\u653e\u4e0b\u8f7d<\/p>\n<\/p>\n<p>120\u9053Python\u9762\u8bd5\u9898.pdf &#xff0c;\u5b8c\u5168\u7248\u5f00\u653e\u4e0b\u8f7d<\/p>\n<p>\u5168\u7f51\u6700\u5168 Pandas\u7684\u5165\u95e8\u4e0e\u9ad8\u7ea7\u6559\u7a0b\u5168\u96c6&#xff0c;\u90fd\u5728\u8fd9\u91cc\u4e86&#xff01;(PDF\u4e0b\u8f7d)<\/p>\n<p>\u70b9\u51fb\u4e0b\u65b9\u201c\u9605\u8bfb\u539f\u6587\u201d\u67e5\u770b\u66f4\u591a<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e25\u6b21\uff0c\u6536\u85cf23\u6b21\u3002\u66f4\u591aPython\u5b66\u4e60\u5185\u5bb9\uff1aipengtao.com\u5728\u6784\u5efa\u73b0\u4ee3Web\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u6027\u80fd\u548c\u5e76\u53d1\u80fd\u529b\u662f\u91cd\u8981\u7684\u8003\u91cf\u56e0\u7d20\u3002\u4f20\u7edf\u7684WSGI\u670d\u52a1\u5668\u5df2\u65e0\u6cd5\u6ee1\u8db3\u5f02\u6b65Web\u6846\u67b6\u7684\u9700\u6c42\uff0c\u800cASGI\uff08Asynchronous Server Gateway Interface\uff09\u6210\u4e3a\u65b0\u4e00\u4ee3Web\u670d\u52a1\u5668\u63a5\u53e3\u7684\u6807\u51c6\u3002Uvicorn \u662f\u4e00\u4e2a\u5feb\u901f\u3001\u8f7b\u91cf\u7ea7\u7684ASGI\u670d\u52a1\u5668\uff0c\u652f\u6301\u5f02\u6b65Web\u6846\u67b6\uff08\u5982FastAPI\u548cStarlette\uff09\u4ee5\u53caH&#8230;_uvicorn\u5e93<\/p>\n","protected":false},"author":2,"featured_media":17055,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81,190,43,44],"topic":[],"class_list":["post-17057","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-python","tag-190","tag-43","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python uvicorn\u5e93\uff1a\u4e00\u6b3e\u9ad8\u6027\u80fd\u7684ASGI\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/17057.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python uvicorn\u5e93\uff1a\u4e00\u6b3e\u9ad8\u6027\u80fd\u7684ASGI\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e25\u6b21\uff0c\u6536\u85cf23\u6b21\u3002\u66f4\u591aPython\u5b66\u4e60\u5185\u5bb9\uff1aipengtao.com\u5728\u6784\u5efa\u73b0\u4ee3Web\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u6027\u80fd\u548c\u5e76\u53d1\u80fd\u529b\u662f\u91cd\u8981\u7684\u8003\u91cf\u56e0\u7d20\u3002\u4f20\u7edf\u7684WSGI\u670d\u52a1\u5668\u5df2\u65e0\u6cd5\u6ee1\u8db3\u5f02\u6b65Web\u6846\u67b6\u7684\u9700\u6c42\uff0c\u800cASGI\uff08Asynchronous Server Gateway Interface\uff09\u6210\u4e3a\u65b0\u4e00\u4ee3Web\u670d\u52a1\u5668\u63a5\u53e3\u7684\u6807\u51c6\u3002Uvicorn \u662f\u4e00\u4e2a\u5feb\u901f\u3001\u8f7b\u91cf\u7ea7\u7684ASGI\u670d\u52a1\u5668\uff0c\u652f\u6301\u5f02\u6b65Web\u6846\u67b6\uff08\u5982FastAPI\u548cStarlette\uff09\u4ee5\u53caH..._uvicorn\u5e93\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/17057.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T15:31:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418153145-680270614c518.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/17057.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/17057.html\",\"name\":\"Python uvicorn\u5e93\uff1a\u4e00\u6b3e\u9ad8\u6027\u80fd\u7684ASGI\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T15:31:46+00:00\",\"dateModified\":\"2025-04-18T15:31:46+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/17057.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/17057.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/17057.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python uvicorn\u5e93\uff1a\u4e00\u6b3e\u9ad8\u6027\u80fd\u7684ASGI\u670d\u52a1\u5668\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python uvicorn\u5e93\uff1a\u4e00\u6b3e\u9ad8\u6027\u80fd\u7684ASGI\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/17057.html","og_locale":"zh_CN","og_type":"article","og_title":"Python uvicorn\u5e93\uff1a\u4e00\u6b3e\u9ad8\u6027\u80fd\u7684ASGI\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e25\u6b21\uff0c\u6536\u85cf23\u6b21\u3002\u66f4\u591aPython\u5b66\u4e60\u5185\u5bb9\uff1aipengtao.com\u5728\u6784\u5efa\u73b0\u4ee3Web\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u6027\u80fd\u548c\u5e76\u53d1\u80fd\u529b\u662f\u91cd\u8981\u7684\u8003\u91cf\u56e0\u7d20\u3002\u4f20\u7edf\u7684WSGI\u670d\u52a1\u5668\u5df2\u65e0\u6cd5\u6ee1\u8db3\u5f02\u6b65Web\u6846\u67b6\u7684\u9700\u6c42\uff0c\u800cASGI\uff08Asynchronous Server Gateway Interface\uff09\u6210\u4e3a\u65b0\u4e00\u4ee3Web\u670d\u52a1\u5668\u63a5\u53e3\u7684\u6807\u51c6\u3002Uvicorn \u662f\u4e00\u4e2a\u5feb\u901f\u3001\u8f7b\u91cf\u7ea7\u7684ASGI\u670d\u52a1\u5668\uff0c\u652f\u6301\u5f02\u6b65Web\u6846\u67b6\uff08\u5982FastAPI\u548cStarlette\uff09\u4ee5\u53caH..._uvicorn\u5e93","og_url":"https:\/\/www.wsisp.com\/helps\/17057.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T15:31:46+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418153145-680270614c518.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/17057.html","url":"https:\/\/www.wsisp.com\/helps\/17057.html","name":"Python uvicorn\u5e93\uff1a\u4e00\u6b3e\u9ad8\u6027\u80fd\u7684ASGI\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T15:31:46+00:00","dateModified":"2025-04-18T15:31:46+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/17057.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/17057.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/17057.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Python uvicorn\u5e93\uff1a\u4e00\u6b3e\u9ad8\u6027\u80fd\u7684ASGI\u670d\u52a1\u5668"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/17057","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=17057"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/17057\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/17055"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=17057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=17057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=17057"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=17057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}