{"id":1103585,"date":"2025-01-08T16:12:00","date_gmt":"2025-01-08T08:12:00","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1103585.html"},"modified":"2025-01-08T16:12:02","modified_gmt":"2025-01-08T08:12:02","slug":"python%e5%a6%82%e4%bd%95%e5%ae%89%e8%a3%85%e7%99%be%e5%ba%a6%e7%bd%91%e7%9b%98","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1103585.html","title":{"rendered":"python\u5982\u4f55\u5b89\u88c5\u767e\u5ea6\u7f51\u76d8"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25065343\/5423e7d1-7199-42ea-b4bd-fa645f592be7.webp\" alt=\"python\u5982\u4f55\u5b89\u88c5\u767e\u5ea6\u7f51\u76d8\" \/><\/p>\n<p><p> <strong>\u4f7f\u7528Python\u5b89\u88c5\u767e\u5ea6\u7f51\u76d8\u7684\u65b9\u6cd5\uff1a\u5b89\u88c5\u767e\u5ea6\u7f51\u76d8\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528pip\u5de5\u5177\u3001\u4e0b\u8f7d\u767e\u5ea6\u7f51\u76d8\u5b89\u88c5\u5305\u3001\u4f7f\u7528API\u8fdb\u884c\u96c6\u6210<\/strong>\u3002\u5176\u4e2d\uff0c\u6700\u63a8\u8350\u7684\u65b9\u6cd5\u662f\u4f7f\u7528pip\u5de5\u5177\u6765\u5b89\u88c5\u767e\u5ea6\u7f51\u76d8\u5ba2\u6237\u7aef\uff0c\u56e0\u4e3a\u8fd9\u79cd\u65b9\u6cd5\u7b80\u5355\u5feb\u6377\uff0c\u5e76\u4e14\u53ef\u4ee5\u786e\u4fdd\u7528\u6237\u59cb\u7ec8\u4f7f\u7528\u6700\u65b0\u7248\u672c\u7684\u767e\u5ea6\u7f51\u76d8\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528pip\u5de5\u5177\u5b89\u88c5\u767e\u5ea6\u7f51\u76d8<\/h3>\n<\/p>\n<p><p>pip\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u4f7f\u7528pip\u53ef\u4ee5\u8f7b\u677e\u5b89\u88c5\u5404\u79cdPython\u5305\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528pip\u5de5\u5177\u5b89\u88c5\u767e\u5ea6\u7f51\u76d8\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u6253\u5f00\u547d\u4ee4\u884c\u5de5\u5177<\/strong>\uff1a\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u6309\u4e0b<code>Win + R<\/code>\u952e\uff0c\u8f93\u5165<code>cmd<\/code>\u5e76\u6309\u4e0b\u56de\u8f66\u952e\uff1b\u5728macOS\u6216Linux\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u6253\u5f00\u7ec8\u7aef\u3002<\/li>\n<li><strong>\u5b89\u88c5\u767e\u5ea6\u7f51\u76d8\u5ba2\u6237\u7aef<\/strong>\uff1a\u5728\u547d\u4ee4\u884c\u5de5\u5177\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5e76\u6309\u4e0b\u56de\u8f66\u952e\uff1a\n<pre><code class=\"language-bash\">pip install b<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>dupcs-py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p>\u8fd9\u5c06\u4f1a\u81ea\u52a8\u4e0b\u8f7d\u5e76\u5b89\u88c5\u767e\u5ea6\u7f51\u76d8\u7684Python\u5ba2\u6237\u7aef\u3002<\/li>\n<\/p>\n<\/ol>\n<p><h3>\u914d\u7f6e\u767e\u5ea6\u7f51\u76d8<\/h3>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>baidupcs-py<\/code>\u547d\u4ee4\u884c\u5de5\u5177\u6765\u767b\u5f55\u548c\u7ba1\u7406\u767e\u5ea6\u7f51\u76d8\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u767b\u5f55\u767e\u5ea6\u7f51\u76d8<\/strong>\uff1a\u5728\u547d\u4ee4\u884c\u5de5\u5177\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5e76\u6309\u4e0b\u56de\u8f66\u952e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">baidupcs-py login<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6309\u7167\u63d0\u793a\u8f93\u5165\u767e\u5ea6\u8d26\u53f7\u548c\u5bc6\u7801\u8fdb\u884c\u767b\u5f55\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u67e5\u770b\u7f51\u76d8\u6587\u4ef6<\/strong>\uff1a\u767b\u5f55\u6210\u529f\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u7f51\u76d8\u4e2d\u7684\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">baidupcs-py ls<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4e0a\u4f20\u6587\u4ef6<\/strong>\uff1a\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5c06\u672c\u5730\u6587\u4ef6\u4e0a\u4f20\u5230\u767e\u5ea6\u7f51\u76d8\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">baidupcs-py upload &lt;\u672c\u5730\u6587\u4ef6\u8def\u5f84&gt; &lt;\u7f51\u76d8\u76ee\u6807\u8def\u5f84&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4e0b\u8f7d\u6587\u4ef6<\/strong>\uff1a\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5c06\u7f51\u76d8\u4e2d\u7684\u6587\u4ef6\u4e0b\u8f7d\u5230\u672c\u5730\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">baidupcs-py download &lt;\u7f51\u76d8\u6587\u4ef6\u8def\u5f84&gt; &lt;\u672c\u5730\u76ee\u6807\u8def\u5f84&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4f7f\u7528API\u8fdb\u884c\u96c6\u6210<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u5728Python\u7a0b\u5e8f\u4e2d\u96c6\u6210\u767e\u5ea6\u7f51\u76d8\u529f\u80fd\uff0c\u53ef\u4ee5\u4f7f\u7528<code>baidupcs-py<\/code>\u63d0\u4f9b\u7684API\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from baidupcs_py import BaiduPCS<\/p>\n<h2><strong>\u521b\u5efaPCS\u5bf9\u8c61<\/strong><\/h2>\n<p>pcs = BaiduPCS()<\/p>\n<h2><strong>\u767b\u5f55\u767e\u5ea6\u7f51\u76d8<\/strong><\/h2>\n<p>pcs.login(username=&#39;your_username&#39;, password=&#39;your_password&#39;)<\/p>\n<h2><strong>\u67e5\u770b\u7f51\u76d8\u6587\u4ef6<\/strong><\/h2>\n<p>files = pcs.list_files(&#39;\/path\/to\/folder&#39;)<\/p>\n<p>for file in files:<\/p>\n<p>    print(file)<\/p>\n<h2><strong>\u4e0a\u4f20\u6587\u4ef6<\/strong><\/h2>\n<p>pcs.upload_file(&#39;local_file_path&#39;, &#39;\/remote_file_path&#39;)<\/p>\n<h2><strong>\u4e0b\u8f7d\u6587\u4ef6<\/strong><\/h2>\n<p>pcs.download_file(&#39;\/remote_file_path&#39;, &#39;local_file_path&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u793a\u4f8b\u4ee3\u7801\uff0c\u53ef\u4ee5\u5728Python\u7a0b\u5e8f\u4e2d\u5b9e\u73b0\u767e\u5ea6\u7f51\u76d8\u7684\u767b\u5f55\u3001\u67e5\u770b\u6587\u4ef6\u3001\u4e0a\u4f20\u6587\u4ef6\u548c\u4e0b\u8f7d\u6587\u4ef6\u7b49\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h3>\u4e0b\u8f7d\u767e\u5ea6\u7f51\u76d8\u5b89\u88c5\u5305<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u4e0d\u60f3\u4f7f\u7528pip\u5de5\u5177\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5\u4ece\u767e\u5ea6\u7f51\u76d8\u5b98\u7f51\u4e0b\u8f7d\u5b89\u88c5\u5305\u8fdb\u884c\u5b89\u88c5\u3002\u4ee5\u4e0b\u662f\u5b89\u88c5\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u4e0b\u8f7d\u5b89\u88c5\u5305<\/strong>\uff1a\u8bbf\u95ee\u767e\u5ea6\u7f51\u76d8\u5b98\u7f51\uff0c\u4e0b\u8f7d\u9002\u7528\u4e8e\u81ea\u5df1\u64cd\u4f5c\u7cfb\u7edf\u7684\u5b89\u88c5\u5305\u3002<\/li>\n<li><strong>\u5b89\u88c5\u767e\u5ea6\u7f51\u76d8<\/strong>\uff1a\u53cc\u51fb\u4e0b\u8f7d\u7684\u5b89\u88c5\u5305\uff0c\u6309\u7167\u63d0\u793a\u5b8c\u6210\u5b89\u88c5\u8fc7\u7a0b\u3002<\/li>\n<li><strong>\u767b\u5f55\u767e\u5ea6\u7f51\u76d8<\/strong>\uff1a\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6253\u5f00\u767e\u5ea6\u7f51\u76d8\u5ba2\u6237\u7aef\uff0c\u8f93\u5165\u767e\u5ea6\u8d26\u53f7\u548c\u5bc6\u7801\u8fdb\u884c\u767b\u5f55\u3002<\/li>\n<\/ol>\n<p><p>\u603b\u7ed3\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u4f7f\u7528pip\u5de5\u5177\u5b89\u88c5\u767e\u5ea6\u7f51\u76d8\u662f\u6700\u63a8\u8350\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u7b80\u5355\u5feb\u6377\u5e76\u4e14\u53ef\u4ee5\u786e\u4fdd\u59cb\u7ec8\u4f7f\u7528\u6700\u65b0\u7248\u672c\u3002<\/li>\n<li>\u914d\u7f6e\u767e\u5ea6\u7f51\u76d8\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u5de5\u5177\u8fdb\u884c\u767b\u5f55\u548c\u7ba1\u7406\u6587\u4ef6\u3002<\/li>\n<li>\u4f7f\u7528API\u8fdb\u884c\u96c6\u6210\u53ef\u4ee5\u5728Python\u7a0b\u5e8f\u4e2d\u5b9e\u73b0\u767e\u5ea6\u7f51\u76d8\u7684\u529f\u80fd\u3002<\/li>\n<li>\u5982\u679c\u4e0d\u60f3\u4f7f\u7528pip\u5de5\u5177\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5\u4e0b\u8f7d\u767e\u5ea6\u7f51\u76d8\u5b89\u88c5\u5305\u8fdb\u884c\u5b89\u88c5\u3002<\/li>\n<\/ul>\n<p><p>\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff0c\u5b89\u88c5\u548c\u4f7f\u7528\u767e\u5ea6\u7f51\u76d8\u90fd\u975e\u5e38\u65b9\u4fbf\uff0c\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u8f7b\u677e\u7ba1\u7406\u548c\u5b58\u50a8\u6587\u4ef6\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528\u767e\u5ea6\u7f51\u76d8API\u8fdb\u884c\u6587\u4ef6\u4e0a\u4f20\u548c\u4e0b\u8f7d\uff1f<\/strong><br \/>\u8981\u5728Python\u4e2d\u4f7f\u7528\u767e\u5ea6\u7f51\u76d8\u7684API\uff0c\u60a8\u9700\u8981\u9996\u5148\u6ce8\u518c\u767e\u5ea6\u5f00\u53d1\u8005\u8d26\u53f7\uff0c\u5e76\u521b\u5efa\u4e00\u4e2a\u5e94\u7528\u4ee5\u83b7\u53d6API\u5bc6\u94a5\u3002\u63a5\u7740\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528requests\u5e93\u53d1\u9001HTTP\u8bf7\u6c42\uff0c\u8fdb\u884c\u6587\u4ef6\u7684\u4e0a\u4f20\u548c\u4e0b\u8f7d\u64cd\u4f5c\u3002\u8be6\u7ec6\u7684\u6b65\u9aa4\u5305\u62ec\u83b7\u53d6access token\uff0c\u6784\u5efaAPI\u8bf7\u6c42\uff0c\u5e76\u5904\u7406\u8fd4\u56de\u7684\u6570\u636e\u3002\u76f8\u5173\u6587\u6863\u53ef\u4ee5\u53c2\u8003\u767e\u5ea6\u7f51\u76d8\u7684\u5f00\u53d1\u8005\u4e2d\u5fc3\u3002<\/p>\n<p><strong>\u6709\u6ca1\u6709\u63a8\u8350\u7684Python\u5e93\u53ef\u4ee5\u5e2e\u52a9\u6211\u4e0e\u767e\u5ea6\u7f51\u76d8\u8fdb\u884c\u4ea4\u4e92\uff1f<\/strong><br \/>\u662f\u7684\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u5f00\u6e90\u7684Python\u5e93\uff0c\u4f8b\u5982BaiduPCS-Py\u3002\u8fd9\u4e9b\u5e93\u63d0\u4f9b\u4e86\u65b9\u4fbf\u7684\u547d\u4ee4\u884c\u754c\u9762\u548cAPI\u63a5\u53e3\uff0c\u8ba9\u60a8\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u6587\u4ef6\u7684\u4e0a\u4f20\u3001\u4e0b\u8f7d\u3001\u5220\u9664\u7b49\u64cd\u4f5c\u3002\u5728\u4f7f\u7528\u8fd9\u4e9b\u5e93\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u60a8\u5df2\u7ecf\u6309\u7167\u76f8\u5173\u8bf4\u660e\u8fdb\u884c\u4e86\u5b89\u88c5\u548c\u914d\u7f6e\u3002<\/p>\n<p><strong>\u5728\u5b89\u88c5\u767e\u5ea6\u7f51\u76d8\u5ba2\u6237\u7aef\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u95ee\u9898\uff1f<\/strong><br \/>\u5728\u5b89\u88c5\u767e\u5ea6\u7f51\u76d8\u5ba2\u6237\u7aef\u4e4b\u524d\uff0c\u786e\u4fdd\u60a8\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e0e\u767e\u5ea6\u7f51\u76d8\u7684\u8981\u6c42\u76f8\u5339\u914d\u3002\u6b64\u5916\uff0c\u68c0\u67e5\u7f51\u7edc\u8fde\u63a5\u662f\u5426\u7a33\u5b9a\uff0c\u4ee5\u907f\u514d\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u51fa\u73b0\u4e2d\u65ad\u3002\u540c\u65f6\uff0c\u5efa\u8bae\u4e0b\u8f7d\u6700\u65b0\u7248\u672c\u7684\u5ba2\u6237\u7aef\uff0c\u4ee5\u83b7\u5f97\u66f4\u597d\u7684\u6027\u80fd\u548c\u5b89\u5168\u6027\u3002\u5982\u679c\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u9047\u5230\u95ee\u9898\uff0c\u53ef\u4ee5\u67e5\u770b\u5b98\u65b9\u652f\u6301\u6587\u6863\u6216\u793e\u533a\u8bba\u575b\u83b7\u53d6\u5e2e\u52a9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4f7f\u7528Python\u5b89\u88c5\u767e\u5ea6\u7f51\u76d8\u7684\u65b9\u6cd5\uff1a\u5b89\u88c5\u767e\u5ea6\u7f51\u76d8\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528pip\u5de5\u5177\u3001\u4e0b\u8f7d\u767e\u5ea6\u7f51\u76d8\u5b89\u88c5\u5305\u3001\u4f7f\u7528API\u8fdb\u884c\u96c6 [&hellip;]","protected":false},"author":3,"featured_media":1103589,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1103585"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1103585"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1103585\/revisions"}],"predecessor-version":[{"id":1103591,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1103585\/revisions\/1103591"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1103589"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1103585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1103585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1103585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}