XML-RPC, WordPress & Python
Versie door Jeroen Strompf (overleg | bijdragen) op 18 okt 2018 om 18:04 (→Mijn eerste XML-RPC-call (okt. 2018))
Installatie python-wordpress-xmlrpc
- python-wordpress-xmlrpc is een Python-library die als interface functioneert tussen Python en Wordpress's XML-RPC-API. Installatie
- Je kunt deze bibliotheek installeren via
pup
ofeasy_install
. Pip heb ik geprobeerd te installeren, maar die liep vast in z'n eigen foutmeldingen - Installatie easy_install:
sudo apt install python-setuptools
- Installatie bibliotheek:
sudo easy_install python-wordpress-xmlrpc
.
Mijn eerste XML-RPC-call (okt. 2018)
Dit werkte, nadat ik de witregel-foutmelding hieronder had verholpen.
#! /usr/bin/python print(">>> 01.py") from wordpress_xmlrpc import Client, WordPressPost from wordpress_xmlrpc.methods.posts import GetPosts, NewPost from wordpress_xmlrpc.methods.users import GetUserInfo wp = Client('http://example.com/xmlrpc.php', 'rpc-account', 'rpc-wachtwoord') wp.call(GetPosts()) # Doesn't do anything wp.call(GetUserInfo()) # Doesn't do anything post = WordPressPost() post.title = 'My new title' post.content = 'This is the body of my new post.' post.terms_names = { 'post_tag': ['test', 'firstpost'], 'category': ['Introductions', 'Tests'] } wp.call(NewPost(post)) print("<<< 01.py")
Foutmelding: ExpatError: XML or text declaration not at start of entity (okt. 2018)
Code:
#! /usr/bin/python from wordpress_xmlrpc import Client, WordPressPost from wordpress_xmlrpc.methods.posts import GetPosts, NewPost from wordpress_xmlrpc.methods.users import GetUserInfo wp = Client('http://bsp.dvb/xmlrpc.php', 'rpc_account', 'rpc_wachtwoord')
Geeft foutmelding:
xml.parsers.expat.ExpatError: XML or text declaration not at start of entity: line 2, column 0
Het schijnt te komen door een onbedoelde witregel doordat WordPress iets doet met dubbele openingstags. Oplossing: [1]