maxcutler / python-wordpress-xmlrpc Goto Github PK
View Code? Open in Web Editor NEWPython library for WordPress XML-RPC integration
Home Page: http://python-wordpress-xmlrpc.rtfd.org
License: MIT License
Python library for WordPress XML-RPC integration
Home Page: http://python-wordpress-xmlrpc.rtfd.org
License: MIT License
https://github.com/maxcutler/python-wordpress-xmlrpc/blob/master/wordpress_xmlrpc/wordpress.py#L95
The Wordpress documentation makes it clear that the field name is post_author
; following convention this might be remapped to author
in this library, but I did not expect it to be remapped to user
and just lost several hours of development time to this bug. (I assumed Wordpress was misbehaving...)
author
.From #26:
In media example:
post.post_thumbnail
should be post.thumbnail
xmlrpc_clent
should be xmlrpc_client
.The test "test_revisions" fails at line 99:
self.assertEqual(2, len(revision_list))
This test points to a WP bug which as been solved http://core.trac.wordpress.org/ticket/22687 , I suppose this is why the test is failing.
Hello,
With the integration of Jetpack being used by many wp.org blogs, does this cover the JSON api at all? I've gone through the docs, and the taxonomy and other wrappers are so handy, it'd be amazing if it could also work with the JSON data.
Cheers,
-Zach
As of WordPress 3.4, we can now work with any post type registered in WordPress.
Makes the library API more flexible so that users can easily extend WordPressPost to specify their custom fields and then return objects of that type when calling the posts
methods.
Max,
Thanks for a great library!
I'm trying to get all my WordPress blog comments in a file, but the comments date ('date_created' field) always shows the current datetime. Any ideas?
# Read all comments in a WordPress 3.4.1 blog
# Language: Python 2.6.5
# Library: Python-wordpress-xmlrpc 2.0
# OS:Ubuntu Linux
#
from wordpress_xmlrpc import Client
from wordpress_xmlrpc.methods import posts
from wordpress_xmlrpc.methods import comments
# change blog URL, WordPress username and password
wp = Client('http://localhost/wordpress/xmlrpc.php', 'admin', 'admin')
# get pages in batches of 20
offset = 0
increment = 20
# see comments in file "wp.out"
fp = open('wp.out', 'w')
while True:
myposts = wp.call(posts.GetPosts({'number': increment, 'offset': offset}))
if len(myposts) == 0:
break # no more posts returned
for mypost in myposts:
fp.write("Post title: %s\n" % mypost.title.encode('UTF-8'))
mycomments = wp.call(comments.GetComments({'post_id': mypost.id, 'number': 1000}))
for mycomment in mycomments:
fp.write("Comment id:%s, status:%s, date created:%s\n" % (mycomment.id, mycomment.status, mycomment.date_created))
fp.write("-------------------------------------\n")
offset = offset + increment
fp.close()
Thanks in advance!
Regards,
Jose
Some minor bugfixes in 2.0 release:
WordPressPost
is missing its terms_names
field.:ref:
s for each release on the changelog page so that they can be easily deeplinked.I am trying to use your library (v2.1) to write a script to replace broken links after a blog migration to Wordpress.com. After retrieving posts and making corrections to the post.body, I
if not(wp.call(EditPost(post.id, post))):
logging.error("Unable to edit post %s" % (post.id))
else:
logging.info("Successfully updated post %s" % (post.id))
Running this consistently yields this error, irrespective of the post in question or whether any changes were made:
Traceback (most recent call last):
File "wplinkrepair.py", line 260, in <module>
fix_errors=args.repair)
File "wplinkrepair.py", line 206, in process_broken_links
if not(wp.call(EditPost(post.id, post))):
File "C:\Python27\lib\site-packages\wordpress_xmlrpc\base.py", line 37, in call
raw_result = server_method(*args)
File "C:\Python27\lib\xmlrpclib.py", line 1224, in __call__
return self.__send(self.__name, args)
File "C:\Python27\lib\xmlrpclib.py", line 1575, in __request
verbose=self.__verbose
File "C:\Python27\lib\xmlrpclib.py", line 1264, in request
return self.single_request(host, handler, request_body, verbose)
File "C:\Python27\lib\xmlrpclib.py", line 1297, in single_request
return self.parse_response(response)
File "C:\Python27\lib\xmlrpclib.py", line 1473, in parse_response
return u.close()
File "C:\Python27\lib\xmlrpclib.py", line 793, in close
raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault 404: 'Invalid attachment ID.'>```
Any suggestions?
Hey Max,
I just noticed this glitch in the GetPostTerms
method: if you pass True to the second arg, to group the terms by their parent taxonomy, only the first term is returned in the list. An example can be found here.
Cheers,
Peter
I'm using the following code to create a new wordpress page. The page is being created successfully, but the template isn't getting set. I've tried setting new_page.template equal to both the file name of the template as well as the name of the template.
new_page = WordPressPage()
new_page.title = state_name + " Market Data"
new_page.template = "page_marketdata.php"
new_page.slug = state_name
new_page.parent_id = '216' #NOTE: Make sure you change this for live site!
new_page.content = raw_html_page
new_page.post_status = 'publish'
wp.call(posts.NewPost(new_page))
Here is the output of pages.GetPagesTemplates:
{'Blog': 'page_blog.php', 'Default': 'default', 'MarketData': 'page_marketdata.php', 'Archive': 'page_archive.php', 'Landing': 'page_landing.php'}
I'm trying the following code to create a post with post_type = 'brand'.
post = WordPressPost()
post.title = 'Sony'
ptype = FieldMap('post_type', default='brand')
post.post_type = ptype
post.description = 'This is a test post from API'
wp.call(NewPost(post, True))
But it always end up with the error xmlrpclib.Fault: <Fault 401: 'Invalid post type.'>
. What am I doing wrong?
I'm getting a build error during setup. Currently running a clean install of Python 3.1.2 under Mac OS X 10.6.5. I get the same results using sudo.
28shaun15:maxcutler-python-wordpress-xmlrpc-028c420 inhumantsar$ python3 setup.py install
running install
running build
running build_py
creating build
creating build/lib
creating build/lib/wordpress_xmlrpc
copying wordpress_xmlrpc/init.py -> build/lib/wordpress_xmlrpc
copying wordpress_xmlrpc/base.py -> build/lib/wordpress_xmlrpc
copying wordpress_xmlrpc/mixins.py -> build/lib/wordpress_xmlrpc
copying wordpress_xmlrpc/wordpress.py -> build/lib/wordpress_xmlrpc
creating build/lib/wordpress_xmlrpc/methods
copying wordpress_xmlrpc/methods/init.py -> build/lib/wordpress_xmlrpc/methods
copying wordpress_xmlrpc/methods/categories.py -> build/lib/wordpress_xmlrpc/methods
copying wordpress_xmlrpc/methods/demo.py -> build/lib/wordpress_xmlrpc/methods
copying wordpress_xmlrpc/methods/options.py -> build/lib/wordpress_xmlrpc/methods
copying wordpress_xmlrpc/methods/posts.py -> build/lib/wordpress_xmlrpc/methods
copying wordpress_xmlrpc/methods/users.py -> build/lib/wordpress_xmlrpc/methods
running install_lib
creating /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc
copying build/lib/wordpress_xmlrpc/init.py -> /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc
copying build/lib/wordpress_xmlrpc/base.py -> /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc
creating /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc/methods
copying build/lib/wordpress_xmlrpc/methods/init.py -> /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc/methods
copying build/lib/wordpress_xmlrpc/methods/categories.py -> /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc/methods
copying build/lib/wordpress_xmlrpc/methods/demo.py -> /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc/methods
copying build/lib/wordpress_xmlrpc/methods/options.py -> /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc/methods
copying build/lib/wordpress_xmlrpc/methods/posts.py -> /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc/methods
copying build/lib/wordpress_xmlrpc/methods/users.py -> /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc/methods
copying build/lib/wordpress_xmlrpc/mixins.py -> /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc
copying build/lib/wordpress_xmlrpc/wordpress.py -> /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc
byte-compiling /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc/init.py to init.pyc
byte-compiling /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc/base.py to base.pyc
byte-compiling /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc/methods/init.py to init.pyc
byte-compiling /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc/methods/categories.py to categories.pyc
byte-compiling /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc/methods/demo.py to demo.pyc
byte-compiling /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc/methods/options.py to options.pyc
byte-compiling /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc/methods/posts.py to posts.pyc
byte-compiling /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc/methods/users.py to users.pyc
byte-compiling /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc/mixins.py to mixins.pyc
byte-compiling /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc/wordpress.py to wordpress.pyc
File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc/wordpress.py", line 53
print data
^
SyntaxError: invalid syntax
running install_egg_info
Writing /Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages/wordpress_xmlrpc-1.1-py3.1.egg-info
PyPI prefers rST formatting for displaying README/long description and GitHub will use rST just as well as it does Markdown.
It is currently difficult to recover from specific failure scenarios because the library does not catch or throw specific exceptions. Some cases that need to be covered:
Hi there
Thanks for your awesome work on this library! I've been using it for over a year to post with no issues. A couple of weeks ago I had some problems with the initial Client connections, returning the following error:
Traceback (most recent call last):
client = Client('http://site.wordpress.com/xmlrpc.php', 'user', 'password')
File "build/bdist.macosx-10.5-x86_64/egg/wordpress_xmlrpc/base.py", line 27, in init
wordpress_xmlrpc.exceptions.ServerConnectionError: <ProtocolError for site.wordpress.com/xmlrpc.php: 301 Moved Permanently>
I emailed Wordpress.com about it, and they said to contact you, and somehow in that process it started working again (maybe a time lockout?). Now it is happening again, and has been locked out since Wednesday with no sign of fixing itself.
Any idea why this might be happening, and how I can fix it?
Thanks!
Please corrent class
class WordPressCategory(WordPressBase):
definition = {
'cat_id': 'categoryId',
'parent_id': 'parent_id',
'name': FieldMap('categoryName', ['categoryName', 'name']),
'description': 'categoryDescription',
'url': 'htmlUrl',
'rss': 'rssUrl',
}
def __str__(self):
return self.name
Changed parentId for parent_id, now Subcategories work find.
I am trying to get a list of all users where the role is 'subscriber', but the list that comes back seems truncated at 50.
from wordpress_xmlrpc import Client
from wordpress_xmlrpc.methods.users import GetUsers
...
wp = Client(url, username, password)
users = wp.call(GetUsers())
subs = []
for u in users:
if 'subscriber' in u.roles:
subs.append((u.email, u.first_name))
return subs
How do I apply the role filter to GetUsers()
and how do I get the complete list, not just the first 50 results?
Thanks,
Mark
I've found some flaws when dealing with dates and RPC.
Can you expose how do you work with them?
Currently I'm converting all dates to UTC prior to sending to WordPress
I can't add or edit any information in some custom fields. I speak about blog post, not another content.
Field with atribute name="url_video" I haven't problem. But for example name="data[url_video]" doesn't work to add/edit.
I think only occurs this with custom field that contains [ ]. Is there any known problem? I can't find anything in Internet. Is a bug, not possible to do or an error in code?
My Python code that works:
client = Client('http://example.com/xmlrpc.php', 'user', 'password')
fields = [ ['video_url', 100], ['video_title', 'yes'] ]
widget = WordPressPost()
widget.title = 'Widget'
widget.content = 'This is the widgets description.'
widget.custom_fields = []
for field in fields:
widget.custom_fields.append(
{'key' : field[0], 'value' : field[1]}
)
widget.terms_names = {
'category': ['MyCategory'],
}
widget.id = client.call(posts.NewPost(widget))
My Python code that doesn't works:
client = Client('http://example.com/xmlrpc.php', 'user', 'password')
fields = [ ['data[video_url]', 100], ['video_title', 'yes'] ]
widget = WordPressPost()
widget.title = 'Widget'
widget.content = 'This is the widgets description.'
widget.custom_fields = []
for field in fields:
widget.custom_fields.append(
{'key' : field[0], 'value' : field[1]}
)
widget.terms_names = {
'category': ['MyCategory'],
}
widget.id = client.call(posts.NewPost(widget))
Hi,
I agree, as requested,
The wp_password field is used to limit access to a specific post through a password, when set up, the post changes from public to password protected just passing that field is enough in xmlrpc.php to set the post_password into the db and rendering the post with a password validation box.
This requirements comes from posting batches and determine which one would or would not be officially published, and in some cases keep restricted access to post to a reduced set of users.
In my tests, by adding 'password':'wp_password' to the definition dictionary it posted fine.
I think it's the only missing method in there too.
Thanks,
I can't seem to find a way to get the name of the person that posted a post in the wp.call(GetPosts())
reply.
Hi
On python 2.7 at debian 7 I'm getting an error when the system converts XML Post Date into Python Tuple (/wordpress_xmlrpc/fieldmaps.py:88)
*** ValueError: time data '2014-02-10 20:24:38' does not match format '%Y%m%dT%H:%M:%S'
It is clear that timetuple()
was expecting '20140210T20:24:38'
- which is very weird to me!
So I'm not sure if the module is really working or if my system have some inconsistency.
The objects from wordpress.py such as WordPressPage, WordPressPost should not raise Exception on :
page = WordPressPage() print page
AttributeError: 'WordPressPage' object has no attribute 'title'
does not work attribute parent_id in class WordPressPage
after adding the page
parent is empty
There is no document on how to use it behind proxy. Can we use it behind proxy?
I'm trying to set some wordpress options via the following function:
opts = dict()
opt = GoogleTools.GetCsvObj(Settings.key, Settings.gid["options"])
for row in opt:
opts[row[0]] = row[1]
output = client.call(options.SetOptions(opts))
The dictionary im passing is being created succeffully on my side, but the script throws the following error in methods\options.py
Traceback (most recent call last):
File "R:/2014.12.04.wordpresshelper/WordpressSyncer.py", line 24, in
set_options()
File "R:/2014.12.04.wordpresshelper/WordpressSyncer.py", line 22, in set_options
output = client.call(options.SetOptions(opts))
File "C:\Python27\lib\site-packages\wordpress_xmlrpc\base.py", line 46, in call
return method.process_result(raw_result)
File "C:\Python27\lib\site-packages\wordpress_xmlrpc\methods\options.py", line 19, in process_result
for key, value in options_dict.items():AttributeError: 'list' object has no attribute 'items'
All my posts made by using python-wordpress-xmlrpc library have their comments disabled. How can I enable it? WordPressPost class has the attribute comment_status, but is not documented what arguments it can receive.
Thanks!
Hi,
I create a user with Author role in wordpress. In python, I can create a new post BUT when I want to edit the same post I get the following error message:
"Sorry, you are not allowed to stick this post"
If I change the user's role to Editor then everything is OK. Why I can not edit my post???
Wordpress: 3.8.3
Python : 2.6.6
python-wordpress-xmlrpc: 2.2
wp = Client('http://www.xxx.xxx/xmlrpc.php', 'authoruser', '123456')
post = WordPressPost()
post.title = 'Test'
post.content = 'This is a wonderful blog post about XML-RPC.'
post.id = wp.call(posts.NewPost(post))
post.post_status = 'publish'
wp.call(posts.EditPost(post.id, post))
post = wp.call(posts.GetPost(post.id))
post.title = 'Post with Tags'
wp.call(posts.EditPost(post.id, post))
xmlrpclib
won't auto-escape characters that are invalid in XML, which can cause operations to fail when strings contain non-ASCII characters.
This library knows enough about the fields to auto-escape/encode those which can contain arbitrary strings (e.g., WordPressPost.title
). Can be as simple as text.encode('ascii', 'xmlcharrefreplace')
when building struct
.
The GetRecentPosts() can only fetch posts of the post type 'post', not any of the custom post types, if defined.
My server is running Wordpress 3.2.1.
The following code:
from wordpress_xmlrpc import Client
wp = Client('<redacted>', '<redacted>', '<redacted>')
results in the exception:
Traceback (most recent call last):
File "test.py", line 2, in <module>
wp = Client('<redacted>', '<redacted>', '<redacted>')
File "/home/pafcu/projects/rsswp/wordpress_xmlrpc/base.py", line 24, in __init__
self.supported_methods = self.server.mt.supportedMethods()
File "/usr/lib/python2.7/xmlrpclib.py", line 1224, in __call__
return self.__send(self.__name, args)
File "/usr/lib/python2.7/xmlrpclib.py", line 1570, in __request
verbose=self.__verbose
File "/usr/lib/python2.7/xmlrpclib.py", line 1264, in request
return self.single_request(host, handler, request_body, verbose)
File "/usr/lib/python2.7/xmlrpclib.py", line 1297, in single_request
return self.parse_response(response)
File "/usr/lib/python2.7/xmlrpclib.py", line 1462, in parse_response
p.feed(data)
File "/usr/lib/python2.7/xmlrpclib.py", line 557, in feed
self._parser.Parse(data, 0)
xml.parsers.expat.ExpatError: XML or text declaration not at start of entity: line 2, column 0
It seems like the library has trouble with the whitespace at the beginning of the reply from the server.
I recently started learning Python, and perhaps this error is related to something else, but here's what I get error when doing an example from the documentation
wp.call(GetUserInfo())
Traceback (most recent call last):
File "<pyshell#7>", line 1, in
wp.call(GetUserInfo())
File "E:\python32\lib\site-packages\wordpress_xmlrpc\wordpress.py", line 50, in repr
return '<%s: %s>' % (self.class.name, unicode(self).encode('utf-8'))
NameError: global name 'unicode' is not defined
Python 3.2.3 Win7
Hi
I am getting this error. I am using latest wordpress 3.4.1 and current version of your code.
Post is still created/Edited so for now I am wrapping it in a try, except and still getting the job done.
Traceback (most recent call last):
File "friday-sermon-updater.py", line 283, in <module>
create_or_update_friday_sermon_post()
File "friday-sermon-updater.py", line 184, in create_or_update_friday_sermon_post
wp.call(EditPost(existing_post.id,friday_post))
File "/usr/local/lib/python2.7/dist-packages/wordpress_xmlrpc/base.py", line 37, in call
raw_result = server_method(*args)
File "/usr/lib/python2.7/xmlrpclib.py", line 1224, in __call__
return self.__send(self.__name, args)
File "/usr/lib/python2.7/xmlrpclib.py", line 1578, in __request
verbose=self.__verbose
File "/usr/lib/python2.7/xmlrpclib.py", line 1264, in request
return self.single_request(host, handler, request_body, verbose)
File "/usr/lib/python2.7/xmlrpclib.py", line 1297, in single_request
return self.parse_response(response)
File "/usr/lib/python2.7/xmlrpclib.py", line 1467, in parse_response
p.feed(data)
File "/usr/lib/python2.7/xmlrpclib.py", line 557, in feed
self._parser.Parse(data, 0)
xml.parsers.expat.ExpatError: junk after document element: line 2, column 0
Traceback (most recent call last):
File "friday-sermon-updater.py", line 283, in <module>
create_or_update_friday_sermon_post()
File "friday-sermon-updater.py", line 184, in create_or_update_friday_sermon_post
wp.call(EditPost(existing_post.id,friday_post))
File "/usr/local/lib/python2.7/dist-packages/wordpress_xmlrpc/base.py", line 37, in call
raw_result = server_method(*args)
File "/usr/lib/python2.7/xmlrpclib.py", line 1224, in __call__
return self.__send(self.__name, args)
File "/usr/lib/python2.7/xmlrpclib.py", line 1578, in __request
verbose=self.__verbose
File "/usr/lib/python2.7/xmlrpclib.py", line 1264, in request
return self.single_request(host, handler, request_body, verbose)
File "/usr/lib/python2.7/xmlrpclib.py", line 1297, in single_request
return self.parse_response(response)
File "/usr/lib/python2.7/xmlrpclib.py", line 1467, in parse_response
p.feed(data)
File "/usr/lib/python2.7/xmlrpclib.py", line 557, in feed
self._parser.Parse(data, 0)
xml.parsers.expat.ExpatError: junk after document element: line 2, column 0
Used to work before version 2.
thanks for your help!
Simple example:
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods import posts
client = Client(...)
post = WordPressPost()
post.title = 'Picture of the Day'
post.content = 'What a lovely picture today!'
post.post_status = 'draft'
post_id = post.id = client.call(posts.NewPost(post))
post1 = WordPressPost()
post1.post_status = 'publish'
post.id = client.call(posts.EditPost(post_id, post1))
Post is published but title is set back to "Untitled".
If now I want original title I need to add a line post1.title = post.title
before post.id = client.call(posts.EditPost(post_id, post1))
Library v 2.1, python 2.7.2, wordpress 3.4.1
Best regards
Hello,
library v 2.1, python 2.7.2
Attaching thumbnails not working.
I use example from http://python-wordpress-xmlrpc.readthedocs.org/en/latest/examples/media.html and image is uploaded to blog but is not attached to post.
What is send to blog with post.id = client.call(posts.NewPost(post))
:
<?xml version='1.0'?>
<methodCall>
<methodName>wp.newPost</methodName>
<params>
<param>
<value><int>0</int></value>
</param>
<param>
<value><string>mymy</string></value>
</param>
<param>
<value><string>mymy</string></value>
</param>
<param>
<value><struct>
<member>
<name>post_status</name>
<value><string>publish</string></value>
</member>
<member>
<name>post_content</name>
<value><string>What a lovely picture today!</string></value>
</member>
<member>
<name>post_type</name>
<value><string>post</string></value>
</member>
<member>
<name>terms</name>
<value><nil/></value></member>
<member>
<name>post_title</name>
<value><string>Picture of the Day</string></value>
</member>
</struct></value>
</param>
</params>
</methodCall>```
I've followed the code at the link below and the post thumbnail is not set...
http://python-wordpress-xmlrpc.readthedocs.org/en/latest/examples/media.html#
The image is uploaded and post is created but no link is made in between them.
Using latest wp from the nightly builds.
Any idea what am I doing wrong?
If possible, add support Python 3.x, which is finally gaining some mainstream traction.
I have been trying to get your example to work, but I couldn't.
I have followed your code exactly as in :
http://python-wordpress-xmlrpc.readthedocs.org/en/latest/overview.html#quick-start
the post is created, but it is uncategorized / has no tags.
this is tested on :
wp 3.2 + xmlrpc modernizer plugin , and on wp 3.4 beta 3
while trying to add custom fields as mentioned in the docs, I noticed that the custom_fields are not by default a list. So I had to do this:
post.custom_fields = []
post.custom_fields.append({"key": "key", "value":"value"})
It works!
Is it possible that we manually don't have to force it as a list?
I'm planning to use this plugin for automated posting.
Since the XMLRPC gateway has so much functionality I'd like to add SSL certificate auth to the Client methods.
May I request a feature enhancement where I can pass in certificate files to the client for connection security?
In order to represent an Object the system do:
WordPressChildClass.__str__
self.__str__
to ascii (str(self)
)self
to utf-8 (.encode('UTF-8')
)Which IMHO is totally wrong because:
I'm currently not sure if any unicode
conversion is made in the request/response processes (the data [eg. self.title] is already unicode, which is great).
That being said the fix I've used is this commit. But I have also make sure to convert all the classes.str output to utf-8.
In fact I'm really not sure if converting all data to utf-8 will catch all WP encoding cases (surely most of them). There is some info about encodings and WordPress in the following links
Use Sphinx to create distinct documentation. Host it on either PyPI or RTFD.org.
Hello,
it would be nice if we could add, edit and delete links from our blog link manager.
Best regards
I use the blog is not in English (Russian).
p = wp.call(GetPosts()) print p
I get the error:
[Traceback (most recent call last):
File "./wpxml.py", line 11, in <module>
print p
File "/home/user/wp/python-wordpress-xmlrpc/wordpress_xmlrpc/wordpress.py", line 51, in __repr__
return '<%s: %s>' % (self.__class__.__name__, str(self).encode('utf-8'))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-10: ordinal not in range(128)
most likely error is UnicodeEncodeError and other descendants of the class WordPressBase in the method __str__
with the non-English contains the string.
I'm sorry for my broken English
python version 2.7.3
Added in WordPress 3.4: http://codex.wordpress.org/XML-RPC_WordPress_API/Taxonomies
Hi, if you make this simple change, then people can easily use a custom transport:
class Client(object):
"""
Connection to a WordPress XML-RPC API endpoint.
To execute XML-RPC methods, pass an instance of an
`XmlrpcMethod`-derived class to `Client`'s `call` method.
"""
def __init__(self, url, username, password, blog_id=0, transport=None):
self.url = url
self.username = username
self.password = password
self.blog_id = blog_id
self.transport = transport
try:
if self.transport:
self.server = xmlrpc_client.\
ServerProxy(url, allow_none=True,
transport=self.transport)
else:
self.server = xmlrpc_client.ServerProxy(url, allow_none=True)
self.supported_methods = self.server.mt.supportedMethods()
except xmlrpc_client.ProtocolError:
e = sys.exc_info()[1]
raise ServerConnectionError(repr(e))
def call(self, method):
if method.method_name not in self.supported_methods:
raise UnsupportedXmlrpcMethodError(method.method_name)
server_method = getattr(self.server, method.method_name)
args = method.get_args(self)
try:
raw_result = server_method(*args)
except xmlrpc_client.Fault:
e = sys.exc_info()[1]
if e.faultCode == 403:
raise InvalidCredentialsError(e.faultString)
elif e.faultCode == 405:
raise XmlrpcDisabledError(e.faultString)
else:
raise
return method.process_result(raw_result)
Whenever you retrieve or create a comment with valid unicode content, the __repr__
method fails on decoding. Seems like it's trying to convert what happens to be a unicode (or ASCII?) string encoded as string, then decoded to UTF. It's only an issue because when I try to print the returned list of Comments from a request, I get the error.
To reproduce:
new_comment = WordPressComment({'content':"\xa0"})
print new_comment
>>> *** UnicodeDecodeError: 'ascii' codec can't decode byte 0xa0 in position 0: ordinal not in range(128)
I think it's the equivalent of doing
print str(u'\xa0')
#or
unicode('\xa0')
But I'm not really familiar with this sort of thing so this could very well be a bad idea, but is it maybe worth trying to use unicode(self)
instead of the str(self).encode('utf-8')
?
Calling GetUsersBlogs doesn't return any WordPressBlog(s) with an isAdmin field, despite the fact that the field is defined.
Example:
client.call(users.GetUsersBlogs())[0].struct
{'url': 'http://localhost/wordpress/', 'blogid': '1', 'xmlrpc': 'http://localhost/wordpress/xmlrpc.php', 'blogName': 'Wordpress Test'}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.