使用XMLRPC连接到本地WordpressDB

2024-04-26 21:36:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图连接到我的本地网站,我用wampserver设置,我可以 通过浏览器连接。 但是,当我尝试通过python连接到它时:

from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.taxonomies import *
from wordpress_xmlrpc.methods.posts import *
from wordpress_xmlrpc.methods.users import *
from wordpress_xmlrpc.methods import *

wp_site = Client("http://localhost/testwp/", "my wp username", "my wp password")

我得到一个错误:

xml.parsers.expat.ExpatError: not well-formed (invalid token): line 3, column 29

是否可以使用xmlrpc连接到本地服务器,或者我做错了什么?你知道吗

谢谢你!你知道吗


Tags: fromimportclient网站mywordpress浏览器users
1条回答
网友
1楼 · 发布于 2024-04-26 21:36:42

可以使用python-wordpress-xmlrpc库连接到本地wp服务器。 根据官方文件,我们需要访问xmlrpc.php文件设置连接时,将文件保存在根wp目录中。在原始问题中提供的片段中,请考虑将最后一行改为:
wp_site = Client("http://localhost/testwp/xmlrpc.php", "my wp username", "my wp password")。你知道吗

获取用户信息的可能示例代码可能如下所示:

from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.taxonomies import *
from wordpress_xmlrpc.methods.posts import *
from wordpress_xmlrpc.methods.users import *
from wordpress_xmlrpc.methods import *

wp_site = Client("http://localhost/testwp/xmlrpc.php", "my_wp_username", "my_wp_password")
user_info = wp_site.call(GetUserInfo())
print(user_info)

相关问题 更多 >