{"id":4422,"date":"2025-08-12T00:05:18","date_gmt":"2025-08-11T16:05:18","guid":{"rendered":"https:\/\/10ccc.cc\/?p=4422"},"modified":"2026-01-07T20:16:08","modified_gmt":"2026-01-07T12:16:08","slug":"python-xml-rpc-%e8%87%aa%e5%8a%a8%e5%8f%91%e6%96%87%e6%b5%8b%e8%af%95","status":"publish","type":"post","link":"https:\/\/10ccc.cc\/?p=4422","title":{"rendered":"WordPress AI Agent\u81ea\u52a8\u53d1\u6587\u6d4b\u8bd5"},"content":{"rendered":"<h1>\u8fd9\u90e8\u5206\u662fAI\u81ea\u52a8\u53d1\u5e03\u7684\u6587\u7ae0<\/h1>\n<p>\u6700\u8fd1\u5728\u63a2\u7d22\u4f7f\u7528AI agent\u603b\u7ed3\u5185\u5bb9\u5e76\u53d1\u5e03\u7b14\u8bb0\u3002\u5c1d\u8bd5\u6839\u636e\u4e0d\u540c\u7684\u5e73\u53f0\u8c03\u6574\u9063\u8bcd\u884c\u6587\u98ce\u683c\u3002\u4fbf\u6709\u4e86\u672c\u6587\uff0c\u63a2\u7d22\u6574\u4e2a\u6d41\u7a0b\u662f\u5426\u80fd\u901a\u7545\u8fd0\u884c\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u7ed9\u8fd9\u7bc7\u6587\u7ae0\u7531AI Agent \u8c03\u7528 Python XML-RPC \u811a\u672c\u81ea\u52a8\u53d1\u5e03\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e0a\u4f20\u7684\u56fe\u7247\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/10ccc.cc\/wp-content\/uploads\/2025\/08\/aa.jpg\" alt=\"\u6d4b\u8bd5\u56fe\u7247\" \/><\/p>\n<p>&nbsp;<\/p>\n<h1>\u811a\u672c\u4ee3\u7801<\/h1>\n<p>\u53ef\u4f9bai agent \u8c03\u7528<\/p>\n<div class=\"dm-code-snippet dark no-background no-background-mobile dm-normal-version\" style=\"background-color:#abb8c3;\" snippet-height=\"\">\n\t\t\t<div class=\"control-language\">\n                <div class=\"dm-buttons\">\n                    <div class=\"dm-buttons-left\">\n                        <div class=\"dm-button-snippet red-button\"><\/div>\n                        <div class=\"dm-button-snippet orange-button\"><\/div>\n                        <div class=\"dm-button-snippet green-button\"><\/div>\n                    <\/div>\n                    <div class=\"dm-buttons-right\">\n                        <a id=\"dm-copy-raw-code\">\n                        <span class=\"dm-copy-text\">Copy Code<\/span>\n                        <span class=\"dm-copy-confirmed\" style=\"display:none\">Copied<\/span>\n                        <span class=\"dm-error-message\" style=\"display:none\">Use a different Browser<\/span><\/a>\n                    <\/div>\n                <\/div>\n                <pre class=\"no-line-numbers\"><code id=\"dm-code-raw\" class=\"no-wrap language-python\"><\/p>\n<pre class=\"dm-pre-admin-side\">import xmlrpc.client\r\nimport base64\r\nimport os\r\n\r\n# \u914d\u7f6e\u533a\r\nWP_URL = \"https:\/\/your_website_domain\/xmlrpc.php\"\r\nWP_USERNAME = \"username\" #app username\r\nWP_PASSWORD = \"app_password\" #app password\r\n\r\nserver = xmlrpc.client.ServerProxy(WP_URL)\r\n\r\n\r\n# 1. \u67e5\u8be2\u6587\u7ae0\u5217\u8868\r\ndef get_recent_posts(count=5):\r\n    posts = server.metaWeblog.getRecentPosts(\"\", WP_USERNAME, WP_PASSWORD, count)\r\n    for post in posts:\r\n        print(f\"[{post['postid']}] {post['title']}\")\r\n    return posts\r\n\r\n\r\n# 2. \u4e0a\u4f20\u56fe\u7247\u5e76\u8fd4\u56deURL\r\ndef upload_image(image_path):\r\n    if not os.path.exists(image_path):\r\n        raise FileNotFoundError(f\"\u627e\u4e0d\u5230\u6587\u4ef6\uff1a{image_path}\")\r\n\r\n    with open(image_path, \"rb\") as f:\r\n        data = f.read()\r\n\r\n    media = {\r\n        'name': os.path.basename(image_path),\r\n        'type': 'image\/jpeg',  # \u6839\u636e\u6587\u4ef6\u7c7b\u578b\u4fee\u6539\r\n        'bits': xmlrpc.client.Binary(data)\r\n    }\r\n\r\n    result = server.metaWeblog.newMediaObject(\"\", WP_USERNAME, WP_PASSWORD, media)\r\n    print(f\"\u56fe\u7247\u4e0a\u4f20\u6210\u529f: {result['url']}\")\r\n    return result['url']\r\n\r\n\r\n# 3. \u53d1\u5e03\u6587\u7ae0\r\ndef publish_post(title, content, categories=None, tags=None):\r\n    post = {\r\n        'title': title,\r\n        'description': content,\r\n        'categories': categories or [],\r\n        'mt_keywords': tags or [],\r\n    }\r\n    post_id = server.metaWeblog.newPost(\"\", WP_USERNAME, WP_PASSWORD, post, True)\r\n    print(f\"\u6587\u7ae0\u53d1\u5e03\u6210\u529f: ID={post_id}\")\r\n    return post_id\r\n\r\n\r\n# 4. \u793a\u4f8b\u8c03\u7528\r\nif __name__ == \"__main__\":\r\n    print(\"=== \u6700\u8fd1\u6587\u7ae0 ===\")\r\n    get_recent_posts(3)\r\n\r\n    print(\"\\n=== \u4e0a\u4f20\u56fe\u7247 ===\")\r\n    img_url = upload_image(\"aa.jpg\")  # \u6362\u6210\u4f60\u7684\u56fe\u7247\u8def\u5f84\r\n\r\n    print(\"\\n=== \u53d1\u5e03\u65b0\u6587\u7ae0 ===\")\r\n    content_html = f\"\"\"\r\n    &lt;h2&gt;\u8fd9\u662f\u81ea\u52a8\u53d1\u5e03\u7684\u6587\u7ae0&lt;\/h2&gt;\r\n    &lt;p&gt;\u8fd9\u7bc7\u6587\u7ae0\u7531 Python XML-RPC \u811a\u672c\u81ea\u52a8\u53d1\u5e03\u3002&lt;\/p&gt;\r\n    &lt;p&gt;\u4e0b\u9762\u662f\u4e0a\u4f20\u7684\u56fe\u7247\uff1a&lt;\/p&gt;\r\n    &lt;img src=\"{img_url}\" alt=\"\u6d4b\u8bd5\u56fe\u7247\" \/&gt;\r\n    \"\"\"\r\n    publish_post(\"Python XML-RPC \u81ea\u52a8\u53d1\u6587\u6d4b\u8bd5\", content_html, categories=[\"\u672a\u5206\u7c7b\"], tags=[\"python\", \"xmlrpc\"])\r\n<\/pre>\n<p><\/code><\/pre>\n\t\t\t<\/div>\n        <\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u90e8\u5206\u662fAI\u81ea\u52a8\u53d1\u5e03\u7684\u6587\u7ae0 \u6700\u8fd1\u5728\u63a2\u7d22\u4f7f\u7528AI agent\u603b\u7ed3\u5185\u5bb9\u5e76\u53d1\u5e03\u7b14\u8bb0\u3002\u5c1d\u8bd5\u6839\u636e\u4e0d\u540c\u7684\u5e73\u53f0\u8c03\u6574\u9063\u8bcd\u884c\u6587\u98ce\u683c\u3002\u4fbf\u6709\u4e86\u672c\u6587\uff0c\u63a2\u7d22 &#8230;<\/p>\n","protected":false},"author":2,"featured_media":4353,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[123,84,82],"tags":[171,172,81,94,93,162],"class_list":["post-4422","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-funny","category-82","tag-agent","tag-agentic","tag-ai","tag-python","tag-workflow","tag-xmlrpc"],"_links":{"self":[{"href":"https:\/\/10ccc.cc\/index.php?rest_route=\/wp\/v2\/posts\/4422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/10ccc.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/10ccc.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/10ccc.cc\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/10ccc.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4422"}],"version-history":[{"count":5,"href":"https:\/\/10ccc.cc\/index.php?rest_route=\/wp\/v2\/posts\/4422\/revisions"}],"predecessor-version":[{"id":4775,"href":"https:\/\/10ccc.cc\/index.php?rest_route=\/wp\/v2\/posts\/4422\/revisions\/4775"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/10ccc.cc\/index.php?rest_route=\/wp\/v2\/media\/4353"}],"wp:attachment":[{"href":"https:\/\/10ccc.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/10ccc.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/10ccc.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}