{"id":934650,"date":"2024-12-26T18:39:01","date_gmt":"2024-12-26T10:39:01","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/934650.html"},"modified":"2024-12-26T18:39:03","modified_gmt":"2024-12-26T10:39:03","slug":"python%e5%a6%82%e4%bd%95%e8%b0%83%e7%94%a8360","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/934650.html","title":{"rendered":"python\u5982\u4f55\u8c03\u7528360"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25071533\/4f960080-aaa4-4fef-adbb-c4585d91d180.webp\" alt=\"python\u5982\u4f55\u8c03\u7528360\" \/><\/p>\n<p><p> <strong>Python\u8c03\u7528360\u7684\u65b9\u6cd5\u4e3b\u8981\u5305\u62ec\uff1a\u4f7f\u7528Python\u7684<code>subprocess<\/code>\u6a21\u5757\u6267\u884c360\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3001\u901a\u8fc7Windows COM\u63a5\u53e3\u4e0e360\u8fdb\u884c\u4ea4\u4e92\u3001\u5229\u7528360\u63d0\u4f9b\u7684API\uff08\u5982\u679c\u6709\u7684\u8bdd\uff09\u3002<\/strong>\u5176\u4e2d\uff0c\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u901a\u8fc7<code>subprocess<\/code>\u6a21\u5757\u6267\u884c360\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u56e0\u4e3a\u8fd9\u79cd\u65b9\u5f0f\u76f4\u63a5\u3001\u7b80\u5355\uff0c\u5e76\u4e14\u4e0d\u9700\u8981360\u63d0\u4f9b\u7279\u5b9a\u7684API\u6216\u63a5\u53e3\u652f\u6301\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528<code>subprocess<\/code>\u6a21\u5757\u8c03\u7528360\uff0c\u4ee5\u53ca\u5176\u4ed6\u65b9\u6cd5\u7684\u53ef\u80fd\u6027\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528<code>subprocess<\/code>\u6a21\u5757\u8c03\u7528360<\/p>\n<\/p>\n<p><p>\u4f7f\u7528Python\u7684<code>subprocess<\/code>\u6a21\u5757\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528\u7cfb\u7edf\u4e0a\u7684\u7a0b\u5e8f\uff0c\u5305\u62ec360\u5b89\u5168\u8f6f\u4ef6\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528<code>subprocess<\/code>\u6a21\u5757\u8c03\u7528360\u7684\u4e00\u822c\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b9a\u4f4d360\u7684\u53ef\u6267\u884c\u6587\u4ef6\u8def\u5f84<\/strong><\/p>\n<\/p>\n<p><p>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c360\u5b89\u5168\u8f6f\u4ef6\u7684\u53ef\u6267\u884c\u6587\u4ef6\u901a\u5e38\u4f4d\u4e8e\u5b89\u88c5\u76ee\u5f55\u4e2d\u3002\u7528\u6237\u9700\u8981\u627e\u5230\u8be5\u8def\u5f84\u4ee5\u4fbf\u5728Python\u4e2d\u8c03\u7528\u3002\u4f8b\u5982\uff0c360\u5b89\u5168\u536b\u58eb\u901a\u5e38\u5b89\u88c5\u5728<code>C:\\Program Files (x86)\\360\\360<a href=\"https:\/\/docs.pingcode.com\/agile\/agile-at-scale\/what-is-safe\" target=\"_blank\">SAFe<\/a><\/code>\u8def\u5f84\u4e0b\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528<code>subprocess<\/code>\u6a21\u5757\u6267\u884c\u53ef\u6267\u884c\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>\u4e00\u65e6\u627e\u5230360\u7684\u53ef\u6267\u884c\u6587\u4ef6\u8def\u5f84\uff0c\u4f7f\u7528Python\u7684<code>subprocess<\/code>\u6a21\u5757\u5c31\u53ef\u4ee5\u6267\u884c\u8be5\u6587\u4ef6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import subprocess<\/p>\n<h2><strong>360\u5b89\u5168\u536b\u58eb\u7684\u53ef\u6267\u884c\u6587\u4ef6\u8def\u5f84<\/strong><\/h2>\n<p>executable_path = r&quot;C:\\Program Files (x86)\\360\\360Safe\\360Safe.exe&quot;<\/p>\n<h2><strong>\u4f7f\u7528subprocess\u8c03\u7528360<\/strong><\/h2>\n<p>subprocess.run([executable_path])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>subprocess.run()<\/code>\u51fd\u6570\u88ab\u7528\u6765\u6267\u884c360\u5b89\u5168\u536b\u58eb\u7684\u4e3b\u7a0b\u5e8f\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8def\u5f84\u4e2d\u5305\u542b\u7a7a\u683c\uff0c\u56e0\u6b64\u9700\u8981\u7528\u5f15\u53f7\u62ec\u8d77\u6765\u6216\u4f7f\u7528\u539f\u59cb\u5b57\u7b26\u4e32\uff08\u4ee5<code>r<\/code>\u5f00\u5934\uff09\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5904\u7406\u8fd4\u56de\u503c<\/strong><\/p>\n<\/p>\n<p><p><code>subprocess.run()<\/code>\u7684\u8fd4\u56de\u503c\u662f\u4e00\u4e2a<code>CompletedProcess<\/code>\u5b9e\u4f8b\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u6267\u884c\u7684\u8fd4\u56de\u7801\u548c\u8f93\u51fa\u4fe1\u606f\u3002\u7528\u6237\u53ef\u4ee5\u6839\u636e\u9700\u8981\u68c0\u67e5\u8fd4\u56de\u7801\u4ee5\u5224\u65ad\u6267\u884c\u662f\u5426\u6210\u529f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u901a\u8fc7Windows COM\u63a5\u53e3\u8c03\u7528360<\/p>\n<\/p>\n<p><p>\u5982\u679c360\u5b89\u5168\u8f6f\u4ef6\u63d0\u4f9bCOM\u63a5\u53e3\uff0c\u7528\u6237\u53ef\u4ee5\u5229\u7528Python\u7684<code>pywin32<\/code>\u5e93\u4e0e\u5176\u8fdb\u884c\u4ea4\u4e92\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528COM\u63a5\u53e3\u8c03\u7528360\u7684\u4e00\u822c\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5pywin32\u5e93<\/strong><\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u7528\u6237\u9700\u8981\u786e\u4fdd\u5b89\u88c5\u4e86<code>pywin32<\/code>\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u901a\u8fc7pip\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pywin32<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u67e5\u627e360\u7684COM\u63a5\u53e3<\/strong><\/p>\n<\/p>\n<p><p>\u7528\u6237\u9700\u8981\u67e5\u627e360\u5b89\u5168\u8f6f\u4ef6\u662f\u5426\u63d0\u4f9bCOM\u63a5\u53e3\uff0c\u5e76\u4e86\u89e3\u63a5\u53e3\u7684\u5177\u4f53\u4f7f\u7528\u65b9\u6cd5\u3002\u8fd9\u901a\u5e38\u9700\u8981\u67e5\u9605360\u7684\u5f00\u53d1\u8005\u6587\u6863\u6216\u901a\u8fc7\u6ce8\u518c\u8868\u67e5\u627e\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528COM\u63a5\u53e3\u8c03\u7528360<\/strong><\/p>\n<\/p>\n<p><p>\u4e00\u65e6\u627e\u5230COM\u63a5\u53e3\uff0c\u7528\u6237\u53ef\u4ee5\u4f7f\u7528<code>pywin32<\/code>\u5e93\u8fdb\u884c\u8c03\u7528\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff08\u5047\u8bbe360\u63d0\u4f9b\u4e86COM\u63a5\u53e3\uff09\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import win32com.client<\/p>\n<h2><strong>\u521b\u5efaCOM\u5bf9\u8c61<\/strong><\/h2>\n<p>obj = win32com.client.Dispatch(&quot;360Safe.Application&quot;)<\/p>\n<h2><strong>\u8c03\u7528360\u7684\u65b9\u6cd5<\/strong><\/h2>\n<p>obj.SomeMethod()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5177\u4f53\u7684\u65b9\u6cd5\u540d\u79f0\u548c\u53c2\u6570\u9700\u8981\u53c2\u8003360\u7684\u6587\u6863\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u5229\u7528360\u63d0\u4f9b\u7684API<\/p>\n<\/p>\n<p><p>\u5982\u679c360\u63d0\u4f9b\u4e86RESTful API\u6216\u5176\u4ed6\u5f62\u5f0f\u7684API\uff0c\u7528\u6237\u53ef\u4ee5\u4f7f\u7528Python\u7684HTTP\u5e93\uff08\u5982<code>requests<\/code>\uff09\u8fdb\u884c\u8c03\u7528\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528API\u8c03\u7528360\u7684\u4e00\u822c\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u67e5\u627e360\u7684API\u6587\u6863<\/strong><\/p>\n<\/p>\n<p><p>\u7528\u6237\u9700\u8981\u67e5\u627e360\u662f\u5426\u63d0\u4f9bAPI\uff0c\u5e76\u4e86\u89e3API\u7684\u5177\u4f53\u4f7f\u7528\u65b9\u6cd5\u3002\u8fd9\u901a\u5e38\u9700\u8981\u8bbf\u95ee360\u7684\u5f00\u53d1\u8005\u7f51\u7ad9\u6216\u901a\u8fc7\u8054\u7cfb360\u7684\u6280\u672f\u652f\u6301\u83b7\u53d6\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528API\u8fdb\u884c\u8c03\u7528<\/strong><\/p>\n<\/p>\n<p><p>\u4e00\u65e6\u627e\u5230API\u6587\u6863\uff0c\u7528\u6237\u53ef\u4ee5\u4f7f\u7528<code>requests<\/code>\u5e93\u8fdb\u884cHTTP\u8bf7\u6c42\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff08\u5047\u8bbe360\u63d0\u4f9b\u4e86API\uff09\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<h2><strong>360 API\u7684URL<\/strong><\/h2>\n<p>api_url = &quot;https:\/\/api.360.cn\/some_endpoint&quot;<\/p>\n<h2><strong>\u53d1\u9001GET\u8bf7\u6c42<\/strong><\/h2>\n<p>response = requests.get(api_url)<\/p>\n<h2><strong>\u5904\u7406\u54cd\u5e94<\/strong><\/h2>\n<p>if response.status_code == 200:<\/p>\n<p>    data = response.json()<\/p>\n<p>    print(data)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;F<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>led to call API:&quot;, response.status_code)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5177\u4f53\u7684API\u7aef\u70b9\u548c\u53c2\u6570\u9700\u8981\u53c2\u8003360\u7684API\u6587\u6863\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u4e09\u79cd\u65b9\u6cd5\uff0c\u7528\u6237\u53ef\u4ee5\u5728Python\u4e2d\u8c03\u7528360\u5b89\u5168\u8f6f\u4ef6\u3002\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u7528<code>subprocess<\/code>\u6a21\u5757\u76f4\u63a5\u6267\u884c360\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u56e0\u4e3a\u8fd9\u79cd\u65b9\u6cd5\u7b80\u5355\u76f4\u63a5\uff0c\u4e0d\u9700\u8981360\u63d0\u4f9b\u7279\u5b9a\u7684API\u6216\u63a5\u53e3\u652f\u6301\u3002\u7136\u800c\uff0c\u5982\u679c\u9700\u8981\u66f4\u590d\u6742\u7684\u4ea4\u4e92\uff0c\u7528\u6237\u53ef\u4ee5\u8003\u8651\u4f7f\u7528COM\u63a5\u53e3\u6216API\uff08\u5982\u679c360\u63d0\u4f9b\u7684\u8bdd\uff09\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\u53d6\u51b3\u4e8e\u7528\u6237\u7684\u5177\u4f53\u9700\u6c42\u548c360\u7684\u652f\u6301\u60c5\u51b5\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8c03\u7528360\u7684API\uff1f<\/strong><br \/>\u5728Python\u4e2d\u8c03\u7528360\u7684API\uff0c\u9996\u5148\u9700\u8981\u6ce8\u518c360\u7684\u5f00\u53d1\u8005\u8d26\u53f7\uff0c\u5e76\u7533\u8bf7\u76f8\u5e94\u7684API\u5bc6\u94a5\u3002\u5b89\u88c5\u8bf7\u6c42\u5e93\uff08\u5982<code>requests<\/code>\uff09\u6765\u5904\u7406HTTP\u8bf7\u6c42\u3002\u4f7f\u7528API\u6587\u6863\u4e2d\u63d0\u4f9b\u7684\u63a5\u53e3\uff0c\u6784\u5efa\u8bf7\u6c42\uff0c\u5305\u62ec\u5fc5\u8981\u7684\u53c2\u6570\u548c\u5bc6\u94a5\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">import requests\n\nurl = &#39;https:\/\/api.360.com\/your_endpoint&#39;\nparams = {\n    &#39;api_key&#39;: &#39;your_api_key&#39;,\n    &#39;param1&#39;: &#39;value1&#39;,\n    &#39;param2&#39;: &#39;value2&#39;\n}\nresponse = requests.get(url, params=params)\ndata = response.json()\nprint(data)\n<\/code><\/pre>\n<p><strong>\u5728\u8c03\u7528360 API\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u4e8b\u9879\uff1f<\/strong><br \/>\u8c03\u7528360 API\u65f6\uff0c\u9700\u8981\u6ce8\u610fAPI\u8c03\u7528\u7684\u9891\u7387\u9650\u5236\u548c\u6570\u636e\u683c\u5f0f\u8981\u6c42\u3002\u786e\u4fdd\u4f60\u5904\u7406\u597d\u5f02\u5e38\u60c5\u51b5\uff0c\u4f8b\u5982\u7f51\u7edc\u95ee\u9898\u6216API\u8fd4\u56de\u9519\u8bef\u4fe1\u606f\u3002\u6b64\u5916\uff0c\u4e86\u89e3\u6bcf\u4e2a\u63a5\u53e3\u7684\u8c03\u7528\u65b9\u5f0f\u548c\u8fd4\u56de\u7ed3\u679c\u7ed3\u6784\uff0c\u4ee5\u4fbf\u6b63\u786e\u89e3\u6790\u6570\u636e\u3002\u4fdd\u6301API\u5bc6\u94a5\u7684\u5b89\u5168\uff0c\u907f\u514d\u6cc4\u9732\u7ed9\u4e0d\u53ef\u4fe1\u7684\u7b2c\u4e09\u65b9\u3002<\/p>\n<p><strong>\u5982\u679c\u8c03\u7528360 API\u65f6\u51fa\u73b0\u9519\u8bef\uff0c\u5e94\u8be5\u5982\u4f55\u6392\u67e5\uff1f<\/strong><br \/>\u5f53\u8c03\u7528360 API\u51fa\u73b0\u9519\u8bef\u65f6\uff0c\u9996\u5148\u68c0\u67e5\u8bf7\u6c42\u7684URL\u548c\u53c2\u6570\u662f\u5426\u6b63\u786e\u3002\u53ef\u4ee5\u67e5\u770bAPI\u8fd4\u56de\u7684\u9519\u8bef\u4fe1\u606f\uff0c\u901a\u5e38\u4f1a\u63d0\u4f9b\u9519\u8bef\u4ee3\u7801\u548c\u63cf\u8ff0\u3002\u786e\u4fdd\u4f60\u7684\u7f51\u7edc\u8fde\u63a5\u6b63\u5e38\uff0c\u5e76\u68c0\u67e5\u662f\u5426\u8d85\u8fc7\u4e86API\u8c03\u7528\u7684\u9650\u5236\u3002\u5982\u679c\u95ee\u9898\u4f9d\u7136\u5b58\u5728\uff0c\u53ef\u4ee5\u67e5\u9605360\u7684\u5f00\u53d1\u8005\u6587\u6863\u6216\u793e\u533a\u8bba\u575b\uff0c\u5bfb\u627e\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u8c03\u7528360\u7684\u65b9\u6cd5\u4e3b\u8981\u5305\u62ec\uff1a\u4f7f\u7528Python\u7684subprocess\u6a21\u5757\u6267\u884c360\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3001\u901a\u8fc7W [&hellip;]","protected":false},"author":3,"featured_media":934654,"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\/934650"}],"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=934650"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/934650\/revisions"}],"predecessor-version":[{"id":934658,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/934650\/revisions\/934658"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/934654"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=934650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=934650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=934650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}