{"id":91865,"date":"2026-08-08T16:01:11","date_gmt":"2026-08-08T08:01:11","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/91865.html"},"modified":"2026-08-08T16:01:11","modified_gmt":"2026-08-08T08:01:11","slug":"%e7%bc%96%e7%a8%8b%e5%90%af%e8%92%99%ef%bd%9cscratch-%e8%bd%ac-python-%e7%b3%bb%e5%88%97%e7%ac%ac-19-%e5%a4%a9%ef%bc%9aai-api-%e8%b0%83%e7%94%a8%e5%85%a5%e9%97%a8%ef%bc%88requests-json-%e5%a4%a7","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/91865.html","title":{"rendered":"\u7f16\u7a0b\u542f\u8499\uff5cScratch \u8f6c Python \u7cfb\u5217\u7b2c 19 \u5929\uff1aAI API \u8c03\u7528\u5165\u95e8\uff08requests + JSON + \u5927\u6a21\u578b\u5bf9\u63a5\u5b9e\u6218\uff09"},"content":{"rendered":"<p>&#x1f4da; \u7cfb\u5217\u5b9a\u4f4d&#xff1a;\u4ece Scratch \u79ef\u6728\u5230 Python \u4ee3\u7801&#xff0c;\u53cc\u5411\u5bf9\u7167\u5b66 AI \u7f16\u7a0b \u270d\ufe0f \u4f5c\u8005&#xff1a;\u6885\u96c5\u8fbe\u7f16\u7a0b\u5de5\u4f5c\u5ba4 &#x1f3af; \u672c\u7bc7\u96be\u5ea6&#xff1a;\u2b50\u2b50\u2b50\u2b50\u2b50&#xff08;\u5b9e\u6218\u9ad8\u9636&#xff09;<\/p>\n<hr \/>\n<h3>\u4e00\u3001\u6458\u8981<\/h3>\n<p>Scratch \u8f6c Python \u7cfb\u5217\u7b2c 19 \u5929\u2014\u2014\u4eca\u5929\u662f\u8ba9\u4f60\u7684 Python \u771f\u7684\u4f1a\u8bf4\u8bdd\u7684\u4e00\u5929&#xff01;\u8fc7\u53bb 18 \u5929\u6211\u4eec\u5199\u7684 AI Agent \u56de\u590d\u90fd\u662f&#034;\u9884\u8bbe\u8bdd\u672f&#034;&#xff0c;\u672c\u7bc7\u7ec8\u4e8e\u8981\u63a5\u771f\u5b9e\u5927\u6a21\u578b API&#xff1a;\u7528 requests \u5e93\u53d1\u9001 HTTP \u8bf7\u6c42\u3001\u7ec4\u88c5 JSON Body\u3001\u5e26\u4e0a\u9274\u6743 Key\u3001\u5904\u7406\u54cd\u5e94&#xff0c;\u8ba9\u4f60\u7684 Agent \u4ece&#034;\u80cc\u53f0\u8bcd&#034;\u8fdb\u5316\u5230&#034;\u771f\u7684\u4f1a\u601d\u8003&#034;\u3002\u672c\u7bc7\u540c\u65f6\u8bb2\u6e05\u695a API \u8c03\u7528\u56db\u5927\u5173\u952e\u70b9\u2014\u2014\u9274\u6743 \/ \u8d85\u65f6 \/ \u91cd\u8bd5 \/ \u9519\u8bef\u5904\u7406&#xff0c;\u5e76\u7ed9\u51fa\u53ef\u76f4\u63a5\u8dd1\u8d77\u6765\u7684\u5927\u6a21\u578b\u5bf9\u63a5 Demo&#xff08;\u542b DeepSeek\u3001\u901a\u4e49\u5343\u95ee\u3001\u6263\u5b50\u4e09\u6761\u5907\u9009\u8def\u5f84&#xff09;&#xff0c;\u4e00\u6b21\u5b66\u4f1a\u901a\u7528\u5957\u8def\u3002<\/p>\n<hr \/>\n<h3>\u4e8c\u3001\u672c\u8282\u8bfe\u5b66\u4e60\u76ee\u6807<\/h3>\n<li>&#x1f3af; \u638c\u63e1 requests \u5e93\u56db\u5927\u7528\u6cd5&#xff1a;GET \/ POST \/ headers \/ json \u53c2\u6570<\/li>\n<li>&#x1f3af; \u638c\u63e1 API \u9274\u6743 4 \u79cd\u4e3b\u6d41\u65b9\u5f0f&#xff1a;URL \u53c2\u6570 \/ Header Bearer \/ Basic \/ \u81ea\u5b9a\u4e49<\/li>\n<li>&#x1f3af; \u5b66\u4f1a JSON \u8bf7\u6c42\u4f53\u62fc\u88c5 &#043; \u54cd\u5e94\u89e3\u6790 \u7684\u5b8c\u6574\u94fe\u8def<\/li>\n<li>&#x1f3af; AI \u5e94\u7528\u573a\u666f&#xff1a;\u628a Day 15-18 \u7684 Agent \u63a5\u5165\u771f\u5b9e\u5927\u6a21\u578b API&#xff0c;\u505a\u51fa\u4e00\u4e2a&#034;\u4f1a\u601d\u8003&#034;\u7684 AI \u52a9\u624b<\/li>\n<hr \/>\n<h3>\u4e09\u3001\u4e13\u4e1a\u540d\u8bcd\u901a\u4fd7\u91ca\u4e49<\/h3>\n<table>\n<tr>\u540d\u8bcd\u901a\u4fd7\u89e3\u91caScratch \u7c7b\u6bd4<\/tr>\n<tbody>\n<tr>\n<td>API<\/td>\n<td>Application Programming Interface&#xff0c;\u7a0b\u5e8f\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1\u7684\u63a5\u53e3<\/td>\n<td>\u522b\u4eba\u5bb6\u7684\u821e\u53f0\u5f00\u653e\u4e86\u51e0\u4e2a&#034;\u5e7f\u64ad\u6d88\u606f&#034;\u901a\u9053\u8ba9\u4f60\u7528<\/td>\n<\/tr>\n<tr>\n<td>HTTP \u8bf7\u6c42<\/td>\n<td>\u4f60\u7684\u7a0b\u5e8f\u53bb\u7f51\u4e0a\u8bf7\u522b\u4eba\u505a\u4e8b\u7684&#034;\u6807\u51c6\u4fe1\u5c01&#034;<\/td>\n<td>\u7cbe\u7075\u5e7f\u64ad\u6d88\u606f\u7ed9\u8fdc\u65b9\u7684\u821e\u53f0&#xff0c;\u7b49\u56de\u5e94<\/td>\n<\/tr>\n<tr>\n<td>GET \/ POST<\/td>\n<td>\u5e38\u89c1\u4e24\u79cd\u8bf7\u6c42\u65b9\u5f0f&#xff1a;GET \u62ff\u6570\u636e&#xff0c;POST \u63d0\u4ea4\u6570\u636e<\/td>\n<td>\u5e7f\u64ad\u67e5\u8be2 vs \u5e7f\u64ad\u63d0\u4ea4\u8868\u5355<\/td>\n<\/tr>\n<tr>\n<td>Headers&#xff08;\u8bf7\u6c42\u5934&#xff09;<\/td>\n<td>\u4fe1\u5c01\u4e0a\u7684\u9644\u52a0\u4fe1\u606f&#xff0c;\u6bd4\u5982&#034;\u6211\u662f\u8c01&#034;\u201c\u8981\u4ec0\u4e48\u683c\u5f0f\u201d<\/td>\n<td>\u5e7f\u64ad\u6d88\u606f\u9644\u5e26\u7684\u81ea\u5b9a\u4e49\u53d8\u91cf<\/td>\n<\/tr>\n<tr>\n<td>Body&#xff08;\u8bf7\u6c42\u4f53&#xff09;<\/td>\n<td>\u4fe1\u5c01\u91cc\u88c5\u7684\u5177\u4f53\u5185\u5bb9&#xff0c;\u4e00\u822c\u662f JSON<\/td>\n<td>\u5e7f\u64ad\u6d88\u606f\u5e26\u7684\u5b8c\u6574\u5185\u5bb9\u5305<\/td>\n<\/tr>\n<tr>\n<td>API Key<\/td>\n<td>\u4f60\u7684\u4e13\u5c5e\u901a\u884c\u8bc1&#xff0c;\u8bc1\u660e&#034;\u6211\u662f\u4ed8\u8d39\u7528\u6237\u53ef\u4ee5\u8c03&#034;<\/td>\n<td>\u821e\u53f0\u5165\u573a\u5238&#xff0c;\u6ca1\u5b83\u4e0d\u8ba9\u8fdb<\/td>\n<\/tr>\n<tr>\n<td>\u54cd\u5e94&#xff08;Response&#xff09;<\/td>\n<td>\u670d\u52a1\u5668\u7ed9\u4f60\u7684&#034;\u56de\u4fe1&#034;&#xff0c;\u4e00\u822c\u4e5f\u662f JSON<\/td>\n<td>\u8fdc\u65b9\u821e\u53f0\u5e7f\u64ad\u56de\u6765\u7684\u6d88\u606f\u5305<\/td>\n<\/tr>\n<tr>\n<td>\u72b6\u6001\u7801<\/td>\n<td>\u56de\u4fe1\u5f00\u5934\u7684&#034;\u529e\u5f97\u6210\u6ca1&#034;\u6807\u8bb0&#xff1a;200 \u6210\u529f\u3001401 \u6ca1\u6743\u9650\u3001429 \u592a\u9891\u7e41\u2026<\/td>\n<td>\u5e7f\u64ad\u56de\u6267\u4e0a\u7684\u6210\u529f\/\u5931\u8d25\u6807\u8bb0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u56db\u3001\u5206\u6a21\u5757\u53cc\u5411\u5bf9\u7167\u77e5\u8bc6\u70b9<\/h3>\n<h4>\u6a21\u5757 1&#xff1a;requests \u57fa\u7840\u8bf7\u6c42<\/h4>\n<p>Scratch \u79ef\u6728\u903b\u8f91&#xff1a;<\/p>\n<p>Scratch \u91cc&#034;\u5e7f\u64ad\u6d88\u606f&#034;\u662f\u628a\u6d88\u606f\u9001\u7ed9\u821e\u53f0\u4e0a\u5176\u4ed6\u7cbe\u7075&#xff1b;requests \u662f\u628a\u6d88\u606f\u9001\u5230\u4e92\u8054\u7f51\u4e0a\u53e6\u4e00\u53f0\u7535\u8111\u3002\u6838\u5fc3\u52a8\u4f5c\u90fd\u662f&#034;\u53d1\u6d88\u606f \u2192 \u7b49\u56de\u590d&#034;\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260808080109-6a76e245adb66.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>Python \u6e90\u7801&#xff08;\u542b Scratch \u79ef\u6728\u6ce8\u91ca&#xff09;&#xff1a;<\/p>\n<p><span class=\"token keyword\">import<\/span> requests<\/p>\n<p><span class=\"token comment\"># \u3010Scratch\u79ef\u6728\u3011\u5e7f\u64ad\u6d88\u606f (GET \u8bf7\u6c42) \u5230 (\u767e\u5ea6)<\/span><br \/>\nresponse <span class=\"token operator\">&#061;<\/span> requests<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;https:\/\/www.baidu.com&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u3010Scratch\u79ef\u6728\u3011\u8bfb\u53d6\u56de\u6267\u7684 (\u72b6\u6001\u7801)<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u72b6\u6001\u7801:&#034;<\/span><span class=\"token punctuation\">,<\/span> response<span class=\"token punctuation\">.<\/span>status_code<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u3010Scratch\u79ef\u6728\u3011\u8bfb\u53d6\u56de\u6267\u7684 (\u6587\u672c\u5185\u5bb9)<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u524d 100 \u5b57:&#034;<\/span><span class=\"token punctuation\">,<\/span> response<span class=\"token punctuation\">.<\/span>text<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">:<\/span><span class=\"token number\">100<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff1a;<\/p>\n<p>\u72b6\u6001\u7801: 200<br \/>\n\u524d 100 \u5b57: &lt;!DOCTYPE html&gt;&lt;!&#8211;STATUS OK&#8211;&gt;&lt;html&gt; &lt;head&gt;&lt;meta http-equiv&#061;&#034;content-type&#034;&#8230;<\/p>\n<p>\u6838\u5fc3\u6613\u9519\u8bf4\u660e&#xff1a;<\/p>\n<ul>\n<li>requests \u662f\u7b2c\u4e09\u65b9\u5e93&#xff0c;\u9700\u8981 pip install requests \u624d\u80fd\u7528<\/li>\n<li>response.text \u662f\u5b57\u7b26\u4e32&#xff0c;response.json() \u624d\u80fd\u81ea\u52a8\u89e3\u6790 JSON<\/li>\n<\/ul>\n<hr \/>\n<h4>\u6a21\u5757 2&#xff1a;POST &#043; JSON Body &#043; Headers<\/h4>\n<p>Scratch \u79ef\u6728\u903b\u8f91&#xff1a;<\/p>\n<p>Scratch \u5e7f\u64ad\u6d88\u606f\u53ef\u4ee5\u5e26\u4e00\u4e2a\u53d8\u91cf\u3002\u771f\u5b9e API \u4e00\u822c\u8981\u6c42\u4f60\u628a&#034;\u8981\u95ee\u7684\u95ee\u9898&#034;\u5305\u88c5\u6210 JSON \u9001\u8fc7\u53bb&#xff0c;\u540c\u65f6\u5934\u90e8\u8981\u5e26 API Key \u8bc1\u660e\u8eab\u4efd\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260808080109-6a76e245d2c7a.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>Python \u6e90\u7801&#xff08;\u542b Scratch \u79ef\u6728\u6ce8\u91ca&#xff09;&#xff1a;<\/p>\n<p><span class=\"token keyword\">import<\/span> requests<\/p>\n<p>url <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;https:\/\/api.example.com\/chat&#034;<\/span><\/p>\n<p><span class=\"token comment\"># \u3010Scratch\u79ef\u6728\u3011\u65b0\u5efa\u5b57\u5178\u300c\u8bf7\u6c42\u5934\u300d\u2192 \u88c5 API Key<\/span><br \/>\nheaders <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token string\">&#034;Authorization&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;Bearer sk-\u4f60\u7684APIKey&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token string\">&#034;Content-Type&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;application\/json&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\"># \u3010Scratch\u79ef\u6728\u3011\u65b0\u5efa\u5b57\u5178\u300c\u8bf7\u6c42\u4f53\u300d\u2192 \u88c5\u95ee\u9898<\/span><br \/>\npayload <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token string\">&#034;model&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;gpt-3.5-turbo&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token string\">&#034;messages&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;role&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;user&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;content&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;\u4f60\u597d\u5440&#034;<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\"># \u3010Scratch\u79ef\u6728\u3011\u5e7f\u64ad POST \u8bf7\u6c42 (\u5e26\u5934 &#043; \u5e26\u4f53)<\/span><br \/>\nresponse <span class=\"token operator\">&#061;<\/span> requests<span class=\"token punctuation\">.<\/span>post<span class=\"token punctuation\">(<\/span>url<span class=\"token punctuation\">,<\/span> headers<span class=\"token operator\">&#061;<\/span>headers<span class=\"token punctuation\">,<\/span> json<span class=\"token operator\">&#061;<\/span>payload<span class=\"token punctuation\">,<\/span> timeout<span class=\"token operator\">&#061;<\/span><span class=\"token number\">30<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u3010Scratch\u79ef\u6728\u3011\u8bfb\u53d6\u56de\u6267\u7684 JSON \u7ed3\u679c<\/span><br \/>\ndata <span class=\"token operator\">&#061;<\/span> response<span class=\"token punctuation\">.<\/span>json<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>data<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff08;\u793a\u4f8b&#xff09;&#xff1a;<\/p>\n<p>{&#039;id&#039;: &#039;chat-xxx&#039;, &#039;choices&#039;: [{&#039;message&#039;: {&#039;role&#039;: &#039;assistant&#039;, &#039;content&#039;: &#039;\u4f60\u597d\u5440&#xff01;\u5f88\u9ad8\u5174\u89c1\u5230\u4f60&#xff5e;&#039;}}]}<\/p>\n<p>\u6838\u5fc3\u6613\u9519\u8bf4\u660e&#xff1a;<\/p>\n<ul>\n<li>json&#061;payload \u53c2\u6570\u4f1a\u81ea\u52a8\u628a\u5b57\u5178\u5e8f\u5217\u5316\u6210 JSON \u5b57\u7b26\u4e32\u5e76\u52a0 Content-Type: application\/json&#xff0c;\u522b\u5199\u6210 data&#061;payload&#xff08;\u90a3\u6837\u53d1\u7684\u662f\u8868\u5355&#xff09;<\/li>\n<li>timeout&#061;30 \u662f\u5fc5\u987b\u52a0\u7684&#xff01;\u5426\u5219\u63a5\u53e3\u5361\u4f4f\u4f1a\u8ba9\u6574\u4e2a\u7a0b\u5e8f\u4e00\u76f4\u6302\u7740<\/li>\n<\/ul>\n<hr \/>\n<h4>\u6a21\u5757 3&#xff1a;\u8d85\u65f6\u4e0e\u91cd\u8bd5<\/h4>\n<p>Scratch \u79ef\u6728\u903b\u8f91&#xff1a;<\/p>\n<p>Scratch \u5e7f\u64ad\u5982\u679c\u6536\u4e0d\u5230\u56de\u590d\u4e0d\u4f1a\u81ea\u52a8\u91cd\u53d1\u3002\u771f\u5b9e API \u7f51\u7edc\u6296\u4e00\u4e0b\u5c31\u53ef\u80fd\u5931\u8d25&#xff0c;\u6211\u4eec\u8981\u5199&#034;\u6700\u591a\u91cd\u8bd5 3 \u6b21&#034;\u7684\u5065\u58ee\u903b\u8f91\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260808080109-6a76e245e35f5.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>Python \u6e90\u7801&#xff08;\u542b Scratch \u79ef\u6728\u6ce8\u91ca&#xff09;&#xff1a;<\/p>\n<p><span class=\"token keyword\">import<\/span> requests<br \/>\n<span class=\"token keyword\">import<\/span> time<\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">call_api_with_retry<\/span><span class=\"token punctuation\">(<\/span>url<span class=\"token punctuation\">,<\/span> headers<span class=\"token punctuation\">,<\/span> payload<span class=\"token punctuation\">,<\/span> max_retries<span class=\"token operator\">&#061;<\/span><span class=\"token number\">3<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token comment\"># \u3010Scratch\u79ef\u6728\u3011\u91cd\u590d (max_retries) \u6b21<\/span><br \/>\n    <span class=\"token keyword\">for<\/span> attempt <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">range<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> max_retries <span class=\"token operator\">&#043;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">try<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token comment\"># \u3010Scratch\u79ef\u6728\u3011\u53d1\u8bf7\u6c42<\/span><br \/>\n            r <span class=\"token operator\">&#061;<\/span> requests<span class=\"token punctuation\">.<\/span>post<span class=\"token punctuation\">(<\/span>url<span class=\"token punctuation\">,<\/span> headers<span class=\"token operator\">&#061;<\/span>headers<span class=\"token punctuation\">,<\/span> json<span class=\"token operator\">&#061;<\/span>payload<span class=\"token punctuation\">,<\/span> timeout<span class=\"token operator\">&#061;<\/span><span class=\"token number\">30<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token comment\"># \u3010Scratch\u79ef\u6728\u3011\u5982\u679c \u72b6\u6001\u7801 &#061; 200 \u90a3\u4e48\u8fd4\u56de<\/span><br \/>\n            <span class=\"token keyword\">if<\/span> r<span class=\"token punctuation\">.<\/span>status_code <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">200<\/span><span class=\"token punctuation\">:<\/span><br \/>\n                <span class=\"token keyword\">return<\/span> r<span class=\"token punctuation\">.<\/span>json<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token keyword\">else<\/span><span class=\"token punctuation\">:<\/span><br \/>\n                <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;\u7b2c <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>attempt<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\"> \u6b21\u5931\u8d25&#xff1a;\u72b6\u6001\u7801 <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>r<span class=\"token punctuation\">.<\/span>status_code<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">except<\/span> requests<span class=\"token punctuation\">.<\/span>exceptions<span class=\"token punctuation\">.<\/span>RequestException <span class=\"token keyword\">as<\/span> e<span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token comment\"># \u3010Scratch\u79ef\u6728\u3011\u6355\u83b7\u5f02\u5e38&#xff0c;\u6253\u5370\u540e\u91cd\u8bd5<\/span><br \/>\n            <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;\u7b2c <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>attempt<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\"> \u6b21\u5f02\u5e38&#xff1a;<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>e<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token comment\"># \u3010Scratch\u79ef\u6728\u3011\u7b49\u5f85 (2 \u7684 attempt \u6b21\u65b9) \u79d2&#xff08;\u6307\u6570\u9000\u907f&#xff09;<\/span><br \/>\n        time<span class=\"token punctuation\">.<\/span>sleep<span class=\"token punctuation\">(<\/span><span class=\"token number\">2<\/span> <span class=\"token operator\">**<\/span> attempt<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">None<\/span>  <span class=\"token comment\"># \u5168\u90e8\u91cd\u8bd5\u5931\u8d25<\/span><\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff08;\u793a\u4f8b&#xff09;&#xff1a;<\/p>\n<p>\u7b2c 1 \u6b21\u5f02\u5e38&#xff1a;Connection timed out<br \/>\n\u7b2c 2 \u6b21\u5f02\u5e38&#xff1a;Connection timed out<br \/>\n{&#039;choices&#039;: [&#8230;]}<\/p>\n<p>\u6838\u5fc3\u6613\u9519\u8bf4\u660e&#xff1a;<\/p>\n<ul>\n<li>\u6307\u6570\u9000\u907f&#xff08;2, 4, 8 \u79d2&#xff09;\u6bd4&#034;\u6bcf\u6b21\u90fd\u7b49 1 \u79d2&#034;\u66f4\u53cb\u597d&#xff0c;\u80fd\u7ed9\u670d\u52a1\u5668\u5598\u606f\u65f6\u95f4<\/li>\n<li>\u522b\u641e&#034;\u6b7b\u5faa\u73af\u91cd\u8bd5&#034;&#xff0c;\u4e00\u5b9a\u8981\u6709 max_retries \u4e0a\u9650<\/li>\n<\/ul>\n<hr \/>\n<h4>\u6a21\u5757 4&#xff1a;\u54cd\u5e94\u89e3\u6790\u4e0e\u9519\u8bef\u7801\u5224\u65ad<\/h4>\n<p>Scratch \u79ef\u6728\u903b\u8f91&#xff1a;<\/p>\n<p>API \u56de\u6267\u50cf\u4fe1\u5c01&#xff0c;\u91cc\u9762\u6709\u53ef\u80fd\u662f\u6210\u529f\u5185\u5bb9&#xff0c;\u4e5f\u53ef\u80fd\u662f\u9519\u8bef\u8bf4\u660e\u3002\u6211\u4eec\u8981\u6309\u72b6\u6001\u7801\u5206\u4e0d\u540c\u5904\u7406\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260808080110-6a76e24604b61.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>Python \u6e90\u7801&#xff08;\u542b Scratch \u79ef\u6728\u6ce8\u91ca&#xff09;&#xff1a;<\/p>\n<p>r <span class=\"token operator\">&#061;<\/span> requests<span class=\"token punctuation\">.<\/span>post<span class=\"token punctuation\">(<\/span>url<span class=\"token punctuation\">,<\/span> headers<span class=\"token operator\">&#061;<\/span>headers<span class=\"token punctuation\">,<\/span> json<span class=\"token operator\">&#061;<\/span>payload<span class=\"token punctuation\">,<\/span> timeout<span class=\"token operator\">&#061;<\/span><span class=\"token number\">30<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u3010Scratch\u79ef\u6728\u3011\u6839\u636e \u72b6\u6001\u7801 \u5224\u65ad<\/span><br \/>\n<span class=\"token keyword\">if<\/span> r<span class=\"token punctuation\">.<\/span>status_code <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">200<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token comment\"># \u3010Scratch\u79ef\u6728\u3011\u6210\u529f \u2192 \u53d6 JSON \u5185\u5bb9<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u56de\u590d&#xff1a;&#034;<\/span><span class=\"token punctuation\">,<\/span> r<span class=\"token punctuation\">.<\/span>json<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;choices&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;message&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;content&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">elif<\/span> r<span class=\"token punctuation\">.<\/span>status_code <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">401<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u274c API Key \u65e0\u6548&#xff0c;\u8bf7\u68c0\u67e5&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">elif<\/span> r<span class=\"token punctuation\">.<\/span>status_code <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">429<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u26a0\ufe0f \u8bf7\u6c42\u592a\u9891\u7e41&#xff0c;\u7a0d\u540e\u518d\u8bd5&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">elif<\/span> r<span class=\"token punctuation\">.<\/span>status_code <span class=\"token operator\">&gt;&#061;<\/span> <span class=\"token number\">500<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u26a0\ufe0f \u670d\u52a1\u5668\u51fa\u9519&#xff0c;\u7a0d\u540e\u91cd\u8bd5&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">else<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;\u5176\u4ed6\u9519\u8bef&#xff1a;<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>r<span class=\"token punctuation\">.<\/span>status_code<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\"> &#8211; <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>r<span class=\"token punctuation\">.<\/span>text<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff08;\u793a\u4f8b&#xff09;&#xff1a;<\/p>\n<p>\u56de\u590d&#xff1a; \u4f60\u597d\u5440&#xff01;\u5f88\u9ad8\u5174\u89c1\u5230\u4f60&#xff5e;<\/p>\n<p>\u6838\u5fc3\u6613\u9519\u8bf4\u660e&#xff1a;<\/p>\n<ul>\n<li>r.json() \u5982\u679c\u54cd\u5e94\u4e0d\u662f\u5408\u6cd5 JSON \u4f1a\u629b\u5f02\u5e38&#xff0c;\u6700\u597d\u5957 try\/except<\/li>\n<li>\u5927\u6a21\u578b API \u8fd4\u56de\u7ed3\u6784\u5404\u5bb6\u4e0d\u540c&#xff08;OpenAI \u662f choices[0].message.content&#xff0c;\u5176\u4ed6\u5bb6\u53ef\u80fd\u662f output.text&#xff09;&#xff0c;\u52a1\u5fc5\u770b\u6587\u6863<\/li>\n<\/ul>\n<hr \/>\n<h3>\u4e94\u3001\u7efc\u5408\u5b9e\u6218\u9879\u76ee&#xff1a;\u771f\u5b9e\u5927\u6a21\u578b API \u5bf9\u63a5 Demo<\/h3>\n<p>\u7ed9 Day 17 \u7684 CLI \u804a\u5929\u673a\u5668\u4eba\u6362\u4e00\u4e2a&#034;\u771f\u6b63\u7684\u5927\u8111&#034;\u2014\u2014\u628a Agent \u7684 chat() \u4ece&#034;\u9884\u8bbe\u8bdd\u672f&#034;\u6362\u6210&#034;\u8c03\u5927\u6a21\u578b API&#034;\u3002<\/p>\n<h4>Scratch \u79ef\u6728\u601d\u8def<\/h4>\n<li>\u4fdd\u7559 Day 15-16 \u7684 AIRole \u57fa\u7c7b<\/li>\n<li>\u65b0\u589e LLMAgent \u5b50\u7c7b&#xff0c;\u91cd\u5199 chat() \u2192 \u8c03\u7528\u5927\u6a21\u578b API<\/li>\n<li>\u4e09\u6b65&#xff1a;\u62fc\u63d0\u793a\u8bcd \u2192 \u53d1\u8bf7\u6c42 \u2192 \u53d6\u56de\u590d<\/li>\n<li>\u5168\u7a0b try\/except \u515c\u5e95&#xff1a;API \u5931\u8d25\u65f6\u9000\u5316\u6210&#034;\u9884\u8bbe\u8bdd\u672f&#034;&#xff0c;\u4fdd\u8bc1\u7a0b\u5e8f\u4e0d\u5d29<\/li>\n<h4>Python \u5b8c\u6574\u53ef\u8fd0\u884c\u4ee3\u7801&#xff08;\u7247\u6bb5&#xff09;<\/h4>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">LLMAgent<\/span><span class=\"token punctuation\">(<\/span>AIRole<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u63a5\u5165\u771f\u5b9e\u5927\u6a21\u578b API \u7684 Agent&#034;&#034;&#034;<\/span><\/p>\n<p>    API_URL <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;https:\/\/api.deepseek.com\/v1\/chat\/completions&#034;<\/span>  <span class=\"token comment\"># \u53ef\u6362\u6210\u901a\u4e49 \/ \u6263\u5b50<\/span><br \/>\n    MODEL <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;deepseek-chat&#034;<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__init__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> name<span class=\"token punctuation\">,<\/span> role<span class=\"token punctuation\">,<\/span> style<span class=\"token punctuation\">,<\/span> api_key<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token builtin\">super<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span>__init__<span class=\"token punctuation\">(<\/span>name<span class=\"token punctuation\">,<\/span> style<span class=\"token punctuation\">)<\/span><br \/>\n        self<span class=\"token punctuation\">.<\/span>role_name <span class=\"token operator\">&#061;<\/span> role<br \/>\n        self<span class=\"token punctuation\">.<\/span>api_key <span class=\"token operator\">&#061;<\/span> api_key<br \/>\n        self<span class=\"token punctuation\">.<\/span>system_prompt <span class=\"token operator\">&#061;<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;\u4f60\u662f\u4e00\u4e2a<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>style<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">\u7684<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>role<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#xff0c;\u540d\u5b57\u53eb<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>name<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">\u3002\u8bf7\u7528\u7b26\u5408\u4eba\u8bbe\u7684\u65b9\u5f0f\u56de\u7b54\u3002&#034;<\/span><\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">chat<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> user_input<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        headers <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token string\">&#034;Authorization&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;Bearer <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>self<span class=\"token punctuation\">.<\/span>api_key<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">,<\/span><br \/>\n            <span class=\"token string\">&#034;Content-Type&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;application\/json&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        payload <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token string\">&#034;model&#034;<\/span><span class=\"token punctuation\">:<\/span> self<span class=\"token punctuation\">.<\/span>MODEL<span class=\"token punctuation\">,<\/span><br \/>\n            <span class=\"token string\">&#034;messages&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">[<\/span><br \/>\n                <span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;role&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;system&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;content&#034;<\/span><span class=\"token punctuation\">:<\/span> self<span class=\"token punctuation\">.<\/span>system_prompt<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                <span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;role&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;user&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;content&#034;<\/span><span class=\"token punctuation\">:<\/span> user_input<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">,<\/span><br \/>\n            <span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token keyword\">try<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            r <span class=\"token operator\">&#061;<\/span> requests<span class=\"token punctuation\">.<\/span>post<span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">.<\/span>API_URL<span class=\"token punctuation\">,<\/span> headers<span class=\"token operator\">&#061;<\/span>headers<span class=\"token punctuation\">,<\/span> json<span class=\"token operator\">&#061;<\/span>payload<span class=\"token punctuation\">,<\/span> timeout<span class=\"token operator\">&#061;<\/span><span class=\"token number\">30<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            reply <span class=\"token operator\">&#061;<\/span> r<span class=\"token punctuation\">.<\/span>json<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;choices&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;message&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;content&#034;<\/span><span class=\"token punctuation\">]<\/span><br \/>\n        <span class=\"token keyword\">except<\/span> Exception <span class=\"token keyword\">as<\/span> e<span class=\"token punctuation\">:<\/span><br \/>\n            reply <span class=\"token operator\">&#061;<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;[API \u8c03\u7528\u5931\u8d25&#xff0c;\u56de\u9000\u9884\u8bbe]\u6536\u5230&#xff1a;<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>user_input<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><br \/>\n        self<span class=\"token punctuation\">.<\/span>history<span class=\"token punctuation\">.<\/span>append<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;user&#034;<\/span><span class=\"token punctuation\">:<\/span> user_input<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;bot&#034;<\/span><span class=\"token punctuation\">:<\/span> reply<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;\u3010<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>self<span class=\"token punctuation\">.<\/span>role_name<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">\u00b7<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>self<span class=\"token punctuation\">.<\/span>name<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">\u3011<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>reply<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> reply<\/p>\n<p><span class=\"token comment\"># \u5b8c\u6574\u4ee3\u7801\u542b GET\/POST \u6f14\u793a\u3001\u91cd\u8bd5\u5c01\u88c5\u3001\u591a API \u63d0\u4f9b\u5546\u5207\u6362<\/span><br \/>\n<span class=\"token comment\"># \u89c1\u914d\u5957\u6e90\u7801\u6587\u4ef6 day19_code.py<\/span><\/p>\n<p>\u8fd0\u884c\u7ed3\u679c\u9884\u89c8&#xff1a;<\/p>\n<p>&#061;&#061;&#061;&#061;&#061; \u771f\u5b9e\u5927\u6a21\u578b Agent Demo &#061;&#061;&#061;&#061;&#061;<br \/>\n\u4f60 &gt; \u8bf7\u7528\u4e00\u53e5\u8bd7\u5f62\u5bb9\u4eca\u5929\u7684\u5fc3\u60c5<br \/>\n\u3010AI\u52a9\u624b\u00b7\u5c0f\u51cc\u3011\u6e05\u98ce\u5165\u6000\u661f\u672a\u843d&#xff0c;\u4ee3\u7801\u4e3a\u4f34\u4ea6\u60a0\u7136&#xff5e;<br \/>\n\u4f60 &gt; \/exit<br \/>\n\u518d\u89c1&#x1f44b;<\/p>\n<p>&#x1f4a1; \u63d0\u793a&#xff1a;Demo \u91cc api_key \u8bf7\u6362\u6210\u4f60\u81ea\u5df1\u7684&#xff08;DeepSeek\u3001\u901a\u4e49\u5343\u95ee\u3001\u6263\u5b50\u90fd\u6709\u514d\u8d39\u8bd5\u7528\u989d\u5ea6&#xff09;\u3002\u6587\u4ef6\u91cc\u4e5f\u63d0\u4f9b\u4e86&#034;\u79bb\u7ebf mock \u6a21\u5f0f&#034;&#xff0c;\u6ca1 Key \u4e5f\u80fd\u8dd1&#xff0c;\u65b9\u4fbf\u540c\u5b66\u4eec\u5148\u770b\u6d41\u7a0b\u3002<\/p>\n<hr \/>\n<h3>\u516d\u3001\u9ad8\u9891\u6613\u9519\u70b9\u603b\u7ed3<\/h3>\n<li>\u274c \u5fd8\u8bb0 timeout&#xff1a;\u4e0d\u52a0\u8d85\u65f6\u53c2\u6570&#xff0c;\u7f51\u7edc\u5361\u6b7b\u65f6\u7a0b\u5e8f\u6b7b\u9501\u2014\u2014\u6c38\u8fdc\u52a0 timeout<\/li>\n<li>\u274c API Key \u786c\u7f16\u7801\u8fdb\u4ee3\u7801\u4e0a\u4f20 GitHub&#xff1a;\u5c5e\u4e8e\u4e25\u91cd\u4e8b\u6545&#xff0c;\u4f1a\u88ab\u6076\u610f\u5237\u989d\u5ea6\u3002\u8bf7\u7528\u73af\u5883\u53d8\u91cf\u6216\u72ec\u7acb\u914d\u7f6e\u6587\u4ef6<\/li>\n<li>\u274c \u8bef\u7528 data&#061; \u4ee3\u66ff json&#061;&#xff1a;data&#061;payload \u53d1\u7684\u662f\u8868\u5355&#xff0c;json&#061;payload \u624d\u662f JSON \u8bf7\u6c42\u4f53<\/li>\n<li>\u274c \u4e0d\u5904\u7406 429 \u9650\u6d41&#xff1a;\u8bf7\u6c42\u592a\u5feb\u88ab\u9650\u6d41\u540e\u5982\u679c\u4e0d\u52a0\u7b49\u5f85\u76f4\u63a5\u91cd\u8bd5&#xff0c;\u4f1a\u88ab\u62c9\u9ed1<\/li>\n<li>\u274c \u4e0d\u6253\u65e5\u5fd7\u76f2\u8c03&#xff1a;API \u62a5\u9519\u4e0d\u770b response.text&#xff0c;\u53ea\u770b\u72b6\u6001\u7801&#xff0c;\u51fa\u95ee\u9898\u5b9a\u4f4d\u56f0\u96be<\/li>\n<hr \/>\n<h3>\u516b\u3001&#x1f4a1; \u5b66\u4e60\u63d0\u793a<\/h3>\n<p>\u4e3a\u9f13\u52b1\u5927\u5bb6\u52a8\u624b\u7ec3\u4e60\u3001\u5403\u900f\u7f16\u7a0b\u903b\u8f91&#xff0c;\u672c\u7bc7\u4e0d\u63d0\u4f9b Scratch \u6210\u54c1\u6e90\u7801&#xff0c;\u8bf7\u5bf9\u7167\u622a\u56fe\u4eb2\u624b\u642d\u5efa\u79ef\u6728\u5b8c\u6210\u590d\u523b&#xff01; \u914d\u5957 Python \u4ee3\u7801\u53ef\u76f4\u63a5\u590d\u5236\u8fd0\u884c\u5b66\u4e60\u3002<\/p>\n<hr \/>\n<h3>\u4e5d\u3001\u5f80\u671f\u5386\u53f2\u7b14\u8bb0<\/h3>\n<li>\n<p>\u7f16\u7a0b\u542f\u8499&#xff5c;Scratch \u8f6c Python \u7cfb\u5217\u7b2c 1 \u5929&#xff1a;\u53d8\u91cf\u3001\u6570\u5b57\u8fd0\u7b97\u79ef\u6728\u53cc\u5411\u5bf9\u7167&#xff08;AI \u57fa\u7840\u6570\u503c\u8ba1\u7b97\u5b9e\u6218&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u7f16\u7a0b\u542f\u8499&#xff5c;Scratch \u8f6c Python \u7cfb\u5217\u7b2c 2 \u5929&#xff1a;\u5206\u652f\u5224\u65ad if \u79ef\u6728\u53cc\u5411\u5bf9\u7167&#xff08;AI \u6307\u4ee4\u6761\u4ef6\u8fc7\u6ee4\u5b9e\u6218&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u7f16\u7a0b\u542f\u8499&#xff5c;Scratch \u8f6c Python \u7cfb\u5217\u7b2c 3 \u5929&#xff1a;\u5faa\u73af\u91cd\u590d\u79ef\u6728\u53cc\u5411\u5bf9\u7167&#xff08;AI \u6279\u91cf\u5faa\u73af\u5904\u7406&#xff0c;\u5df2\u6536\u5f55 AI Agent \u6280\u672f\u793e\u533a&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u7f16\u7a0b\u542f\u8499&#xff5c;Scratch \u8f6c Python \u7cfb\u5217\u7b2c 4 \u5929&#xff1a;\u5b57\u7b26\u4e32\u6587\u672c\u79ef\u6728\u53cc\u5411\u5bf9\u7167&#xff08;AI \u63d0\u793a\u8bcd\u62fc\u63a5\u3001\u6587\u672c\u6e05\u6d17\u5b9e\u6218&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u7f16\u7a0b\u542f\u8499&#xff5c;Scratch \u8f6c Python \u7cfb\u5217\u7b2c 5 \u5929&#xff1a;\u81ea\u5b9a\u4e49\u79ef\u6728 \/ \u51fd\u6570\u53cc\u5411\u5bf9\u7167&#xff08;AI \u5de5\u5177\u5c01\u88c5\u3001\u91cd\u590d\u6307\u4ee4\u7b80\u5316\u5b9e\u6218&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u7f16\u7a0b\u542f\u8499&#xff5c;Scratch \u8f6c Python \u7cfb\u5217\u7b2c 6 \u5929&#xff1a;\u5217\u8868\u3001\u6570\u7ec4\u79ef\u6728\u53cc\u5411\u5bf9\u7167&#xff08;AI \u5e95\u5c42\u8bed\u6cd5 \/ AI \u6279\u91cf\u6570\u636e\u5904\u7406\u5b9e\u6218&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u7f16\u7a0b\u542f\u8499&#xff5c;Scratch \u8f6c Python \u7cfb\u5217\u7b2c 7 \u5929&#xff1a;\u731c\u6570\u5b57\u5927\u6311\u6218\u00b7\u5347\u7ea7\u7248\u5b9e\u6218&#xff08;AI \u51fa\u9898 &#043; \u4e8c\u5206\u67e5\u627e\u6700\u4f18\u89e3 &#043; \u5b8c\u6574\u547d\u4ee4\u884c\u6e38\u620f \u5df2\u88ab\u6536\u5f55\u5728\u667a\u80fd\u4f53\u5f00\u53d1\u8005\u793e\u533a&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u7f16\u7a0b\u542f\u8499&#xff5c;Scratch \u8f6c Python \u7cfb\u5217\u7b2c8\u5929&#xff1a;\u8282\u594f\u6572\u51fb\u673a\u6e38\u620f\u5b9e\u6218&#xff08;AI\u8282\u594f\u8c31\u751f\u6210\u5b9e\u6218&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u7f16\u7a0b\u542f\u8499&#xff5c;Scratch \u8f6c Python \u7cfb\u5217\u7b2c9\u5929&#xff1a;\u5b57\u5178\/\u54c8\u5e0c\u8868\u79ef\u6728\u53cc\u5411\u5bf9\u7167&#xff08;AI\u5927\u6a21\u578b\u53c2\u6570\u914d\u7f6e\u8868\u5b9e\u6218&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u7f16\u7a0b\u542f\u8499&#xff5c;Scratch \u8f6c Python \u7cfb\u5217\u7b2c 10 \u5929&#xff1a;\u95ee\u7b54\u95ef\u5173\u6e38\u620f\u5b9e\u6218&#xff08;AI \u9898\u5e93\u7ba1\u7406 &#043; \u591a\u5173\u5361\u5267\u672c&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u7f16\u7a0b\u542f\u8499&#xff5c;Scratch \u8f6c Python \u7cfb\u5217\u7b2c 11 \u5929&#xff1a;\u6587\u4ef6\u8bfb\u5199\u79ef\u6728\u53cc\u5411\u5bf9\u7167&#xff08;AI \u8bad\u7ec3\u6570\u636e\u5b58\u53d6\u5b9e\u6218&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u7f16\u7a0b\u542f\u8499&#xff5c;Scratch \u8f6c Python \u7cfb\u5217\u7b2c 12 \u5929&#xff1a;\u8bb0\u5fc6\u7ffb\u724c\u6e38\u620f\u5b9e\u6218&#xff08;AI \u56fe\u6848\u4e3b\u9898\u5305 &#043; \u5b58\u6863\u6392\u884c\u699c \u5df2\u88ab\u6536\u5f55\u57282048 AI\u793e\u533a&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u7f16\u7a0b\u542f\u8499&#xff5c;Scratch \u8f6c Python \u7cfb\u5217\u7b2c 13 \u5929&#xff1a;\u5f02\u5e38\u5904\u7406 try\/except \u79ef\u6728\u53cc\u5411\u5bf9\u7167&#xff08;AI \u63a5\u53e3\u8c03\u7528\u5bb9\u9519\u5b9e\u6218&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u7f16\u7a0b\u542f\u8499&#xff5c;Scratch \u8f6c Python \u7cfb\u5217\u7b2c 14 \u5929&#xff1a;AI \u63d0\u793a\u8bcd\u7ba1\u7406\u5de5\u5177\u5b9e\u6218&#xff08;\u589e\u5220\u6539\u67e5 &#043; \u5b58\u6863\u5bfc\u5165 &#043; \u5f02\u5e38\u515c\u5e95&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u7f16\u7a0b\u542f\u8499&#xff5c;Scratch \u8f6c Python \u7cfb\u5217\u7b2c 15 \u5929&#xff1a;\u7c7b\u4e0e\u5bf9\u8c61\u79ef\u6728\u53cc\u5411\u5bf9\u7167&#xff08;AI \u89d2\u8272\u7c7b\u5c01\u88c5\u5b9e\u6218&#xff09;\u5df2\u88ab\u667a\u80fd\u4f53\u5f00\u53d1\u8005\u793e\u533a\u6536\u5f55<\/p>\n<\/li>\n<li>\n<p>\u7f16\u7a0b\u542f\u8499&#xff5c;Scratch \u8f6c Python \u7cfb\u5217\u7b2c 16 \u5929&#xff1a;\u7ee7\u627f\u4e0e\u591a\u6001\u79ef\u6728\u53cc\u5411\u5bf9\u7167&#xff08;AI Agent \u89d2\u8272\u4f53\u7cfb\u5b9e\u6218&#xff09;\u5df2\u88ab\u667a\u80fd\u4f53\u5f00\u53d1\u8005\u793e\u533a\u6536\u5f55<\/p>\n<\/li>\n<li>\n<p>\u7f16\u7a0b\u542f\u8499&#xff5c;Scratch \u8f6c Python \u7cfb\u5217\u7b2c 17 \u5929&#xff1a;AI \u804a\u5929\u673a\u5668\u4eba\u6e38\u620f\u5b9e\u6218&#xff08;AI \u591a\u89d2\u8272\u5bf9\u8bdd &#043; \u4eba\u8bbe\u5207\u6362\u5b9e\u6218&#xff09;\u5df2\u88abDAMO\u5f00\u53d1\u8005\u77e9\u9635\u6536\u5f55<\/p>\n<\/li>\n<li>\n<p>\u7f16\u7a0b\u542f\u8499&#xff5c;Scratch \u8f6c Python \u7cfb\u5217\u7b2c 18 \u5929&#xff1a;\u6a21\u5757\u5bfc\u5165\u4e0e\u5e38\u7528\u6807\u51c6\u5e93\u79ef\u6728\u53cc\u5411\u5bf9\u7167&#xff08;AI \u5de5\u5177\u7bb1\u6a21\u5757\u5316\u5b9e\u6218&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u7f16\u7a0b\u542f\u8499&#xff5c;\u756a\u5916\u7bc7&#xff1a;AI\u81ea\u5df1\u5b66\u4f1a\u4e86\u653b\u51fb\u7535\u8111\u2014\u2014\u6211\u4eec\u4e3a\u4ec0\u4e48\u66f4\u8981\u8ba9\u5b69\u5b50\u4ece\u5c0f\u7406\u89e3\u7f16\u7a0b<\/p>\n<\/li>\n<hr \/>\n<h3>\u5341\u3001\u4e0b\u4e00\u7ae0\u9884\u544a<\/h3>\n<p>\u7b2c 20 \u5929&#xff1a;\u7efc\u5408\u5927\u9879\u76ee AI Agent \u52a9\u624b&#xff08;\u5168\u7cfb\u5217\u77e5\u8bc6\u4e32\u8054\u6536\u5b98&#xff09;<\/p>\n<p>\u672c\u7cfb\u5217\u6536\u5b98\u5927\u9879\u76ee\u6765\u4e86&#xff01;\u6211\u4eec\u5c06\u628a 20 \u5929\u6240\u6709\u77e5\u8bc6\u4e32\u8d77\u6765&#xff0c;\u505a\u4e00\u4e2a\u771f\u6b63\u53ef\u7528\u7684 AI Agent \u52a9\u624b&#xff1a;<\/p>\n<ul>\n<li>\u591a\u89d2\u8272\u4eba\u8bbe &#043; \u52a8\u6001\u5207\u6362&#xff08;Day 15-17&#xff09;<\/li>\n<li>\u771f\u5b9e\u5927\u6a21\u578b API \u5bf9\u63a5&#xff08;Day 19&#xff09;<\/li>\n<li>\u591a\u8f6e\u4e0a\u4e0b\u6587\u8bb0\u5fc6 &#043; JSON \u5b58\u6863&#xff08;Day 6\/9\/11\/18&#xff09;<\/li>\n<li>\u5b8c\u6574\u5f02\u5e38\u515c\u5e95 &#043; CLI \u4ea4\u4e92&#xff08;Day 13&#xff09;<\/li>\n<li>\u6a21\u5757\u5316\u5de5\u7a0b\u7ed3\u6784&#xff08;Day 18&#xff09;<\/li>\n<li>AI \u573a\u666f&#xff1a;\u4eb2\u624b\u505a\u4e00\u4e2a\u5c5e\u4e8e\u81ea\u5df1\u7684 AI \u52a9\u624b&#xff0c;\u53ef\u4ee5\u6bcf\u5929\u7528&#xff01;<\/li>\n<\/ul>\n<p>\u7cfb\u5217\u5927\u7ed3\u5c40&#xff0c;\u4e00\u8d77\u51b2&#xff01;&#x1f680;<\/p>\n<hr \/>\n<h3>\u5341\u4e00\u3001\u539f\u521b\u58f0\u660e<\/h3>\n<p>\u672c\u6587\u4e3a\u300c\u6885\u96c5\u8fbe\u7f16\u7a0b\u7b14\u8bb0\u300d\u539f\u521b\u6280\u672f\u6559\u7a0b&#xff0c;\u672a\u7ecf\u6388\u6743\u7981\u6b62\u8f6c\u8f7d\u3001\u6d17\u7a3f\u6216\u7528\u4e8e\u5546\u4e1a\u57f9\u8bad\u3002\u8f6c\u8f7d\u5408\u4f5c\u8bf7\u8054\u7cfb\u5de5\u4f5c\u5ba4\u3002\u7cfb\u5217\u5185\u5bb9\u6301\u7eed\u66f4\u65b0\u4e2d&#xff0c;\u6b22\u8fce\u6536\u85cf CSDN \u4e13\u680f\u300c\u7f16\u7a0b\u542f\u8499\u2013scratch\u8f6cpython\u300d\u8ffd\u66f4 &#x1f343;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x1f4da; \u7cfb\u5217\u5b9a\u4f4d&#xff1a;\u4ece Scratch \u79ef\u6728\u5230 Python \u4ee3\u7801&#xff0c;\u53cc\u5411\u5bf9\u7167\u5b66 AI \u7f16\u7a0b \u270d\ufe0f \u4f5c\u8005&#xff1a;\u6885\u96c5\u8fbe\u7f16\u7a0b\u5de5\u4f5c\u5ba4 &#x1f3af; \u672c\u7bc7\u96be\u5ea6&#xff1a;\u2b50\u2b50\u2b50\u2b50\u2b50&#xff08;\u5b9e\u6218\u9ad8\u9636&#xff09; \u4e00\u3001\u6458\u8981<br \/>\nScratch \u8f6c Python \u7cfb\u5217\u7b2c 19 \u5929\u2014\u2014\u4eca\u5929\u662f\u8ba9\u4f60\u7684 Python \u771f\u7684\u4f1a\u8bf4\u8bdd\u7684\u4e00\u5929&#xff01;\u8fc7\u53bb 18 \u5929\u6211\u4eec\u5199\u7684 AI Agent \u56de\u590d\u90fd\u662f\\&#8221;\u9884\u8bbe\u8bdd\u672f\\&#8221;&#xff0c;\u672c\u7bc7\u7ec8<\/p>\n","protected":false},"author":2,"featured_media":91861,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10336,93,81,50,190,4405],"topic":[],"class_list":["post-91865","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-10336","tag-json","tag-python","tag-50","tag-190","tag-4405"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u7f16\u7a0b\u542f\u8499\uff5cScratch \u8f6c Python \u7cfb\u5217\u7b2c 19 \u5929\uff1aAI API \u8c03\u7528\u5165\u95e8\uff08requests + JSON + \u5927\u6a21\u578b\u5bf9\u63a5\u5b9e\u6218\uff09 - \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\/91865.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u7f16\u7a0b\u542f\u8499\uff5cScratch \u8f6c Python \u7cfb\u5217\u7b2c 19 \u5929\uff1aAI API \u8c03\u7528\u5165\u95e8\uff08requests + JSON + \u5927\u6a21\u578b\u5bf9\u63a5\u5b9e\u6218\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"&#x1f4da; \u7cfb\u5217\u5b9a\u4f4d&#xff1a;\u4ece Scratch \u79ef\u6728\u5230 Python \u4ee3\u7801&#xff0c;\u53cc\u5411\u5bf9\u7167\u5b66 AI \u7f16\u7a0b \u270d\ufe0f \u4f5c\u8005&#xff1a;\u6885\u96c5\u8fbe\u7f16\u7a0b\u5de5\u4f5c\u5ba4 &#x1f3af; \u672c\u7bc7\u96be\u5ea6&#xff1a;\u2b50\u2b50\u2b50\u2b50\u2b50&#xff08;\u5b9e\u6218\u9ad8\u9636&#xff09; \u4e00\u3001\u6458\u8981 Scratch \u8f6c Python \u7cfb\u5217\u7b2c 19 \u5929\u2014\u2014\u4eca\u5929\u662f\u8ba9\u4f60\u7684 Python \u771f\u7684\u4f1a\u8bf4\u8bdd\u7684\u4e00\u5929&#xff01;\u8fc7\u53bb 18 \u5929\u6211\u4eec\u5199\u7684 AI Agent \u56de\u590d\u90fd\u662f&quot;\u9884\u8bbe\u8bdd\u672f&quot;&#xff0c;\u672c\u7bc7\u7ec8\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/91865.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-08T08:01:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260808080109-6a76e245adb66.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=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/91865.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/91865.html\",\"name\":\"\u7f16\u7a0b\u542f\u8499\uff5cScratch \u8f6c Python \u7cfb\u5217\u7b2c 19 \u5929\uff1aAI API \u8c03\u7528\u5165\u95e8\uff08requests + JSON + \u5927\u6a21\u578b\u5bf9\u63a5\u5b9e\u6218\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-08T08:01:11+00:00\",\"dateModified\":\"2026-08-08T08:01:11+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/91865.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/91865.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/91865.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u7f16\u7a0b\u542f\u8499\uff5cScratch \u8f6c Python \u7cfb\u5217\u7b2c 19 \u5929\uff1aAI API \u8c03\u7528\u5165\u95e8\uff08requests + JSON + \u5927\u6a21\u578b\u5bf9\u63a5\u5b9e\u6218\uff09\"}]},{\"@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":"\u7f16\u7a0b\u542f\u8499\uff5cScratch \u8f6c Python \u7cfb\u5217\u7b2c 19 \u5929\uff1aAI API \u8c03\u7528\u5165\u95e8\uff08requests + JSON + \u5927\u6a21\u578b\u5bf9\u63a5\u5b9e\u6218\uff09 - \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\/91865.html","og_locale":"zh_CN","og_type":"article","og_title":"\u7f16\u7a0b\u542f\u8499\uff5cScratch \u8f6c Python \u7cfb\u5217\u7b2c 19 \u5929\uff1aAI API \u8c03\u7528\u5165\u95e8\uff08requests + JSON + \u5927\u6a21\u578b\u5bf9\u63a5\u5b9e\u6218\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"&#x1f4da; \u7cfb\u5217\u5b9a\u4f4d&#xff1a;\u4ece Scratch \u79ef\u6728\u5230 Python \u4ee3\u7801&#xff0c;\u53cc\u5411\u5bf9\u7167\u5b66 AI \u7f16\u7a0b \u270d\ufe0f \u4f5c\u8005&#xff1a;\u6885\u96c5\u8fbe\u7f16\u7a0b\u5de5\u4f5c\u5ba4 &#x1f3af; \u672c\u7bc7\u96be\u5ea6&#xff1a;\u2b50\u2b50\u2b50\u2b50\u2b50&#xff08;\u5b9e\u6218\u9ad8\u9636&#xff09; \u4e00\u3001\u6458\u8981 Scratch \u8f6c Python \u7cfb\u5217\u7b2c 19 \u5929\u2014\u2014\u4eca\u5929\u662f\u8ba9\u4f60\u7684 Python \u771f\u7684\u4f1a\u8bf4\u8bdd\u7684\u4e00\u5929&#xff01;\u8fc7\u53bb 18 \u5929\u6211\u4eec\u5199\u7684 AI Agent \u56de\u590d\u90fd\u662f\"\u9884\u8bbe\u8bdd\u672f\"&#xff0c;\u672c\u7bc7\u7ec8","og_url":"https:\/\/www.wsisp.com\/helps\/91865.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-08T08:01:11+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260808080109-6a76e245adb66.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/91865.html","url":"https:\/\/www.wsisp.com\/helps\/91865.html","name":"\u7f16\u7a0b\u542f\u8499\uff5cScratch \u8f6c Python \u7cfb\u5217\u7b2c 19 \u5929\uff1aAI API \u8c03\u7528\u5165\u95e8\uff08requests + JSON + \u5927\u6a21\u578b\u5bf9\u63a5\u5b9e\u6218\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-08T08:01:11+00:00","dateModified":"2026-08-08T08:01:11+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/91865.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/91865.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/91865.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u7f16\u7a0b\u542f\u8499\uff5cScratch \u8f6c Python \u7cfb\u5217\u7b2c 19 \u5929\uff1aAI API \u8c03\u7528\u5165\u95e8\uff08requests + JSON + \u5927\u6a21\u578b\u5bf9\u63a5\u5b9e\u6218\uff09"}]},{"@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\/91865","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=91865"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/91865\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/91861"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=91865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=91865"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=91865"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=91865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}