Code Monkey home page Code Monkey logo

python-wordpress-xmlrpc's Introduction

image

Overview

Python library to interface with a WordPress blog's XML-RPC API.

An implementation of the standard WordPress API methods is provided, but the library is designed for easy integration with custom XML-RPC API methods provided by plugins.

This library was developed against and tested on WordPress 3.5. This library is compatible with Python 2.6+ and 3.2+.

Please see docs for more information: http://python-wordpress-xmlrpc.rtfd.org

python-wordpress-xmlrpc's People

Contributors

benjaminaschultz avatar clockwerx avatar dkuryakin avatar hishamnajam avatar ksomervi avatar masnun avatar maxcutler avatar strycore avatar superflit avatar tankorsmash avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-wordpress-xmlrpc's Issues

Build error during setup

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

Character-escape unicode characters automatically

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.

ExpatError: XML or text declaration not at start of entity

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.

Create Exception classes for common failure modes

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:

  • Conversion failure in FieldMap
  • Connection failure (invalid credentials or URL)
  • Unsupported method
  • Invalid method arguments

Question: how to enable comments in my posts?

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!

SSL certs for connection

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?

Inplace post edits are returning Fault 404: 'Invalid attachment ID.'

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?

Get list of users filtered by role; results limited to 50?

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

Object's __str__ should return empty string

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'

Cannot edit images after upload

When I upload images using client.call(media.UploadFile(data)), the uploaded images cannot be edited in wordpress.

image

I suspect I'm doing something wrong.
Thanks

Documentation typos

From #26:

In media example:

  • post.post_thumbnail should be post.thumbnail
  • xmlrpc_clent should be xmlrpc_client.

New(ish) JSON API support?

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

2.0 Bugfixes

Some minor bugfixes in 2.0 release:

  • WordPressPost is missing its terms_names field.
  • On "Working with Posts" example page, the CPT example is missing proper code styling.
  • Extra "the" before "AuthenticatedMethod" at bottom of custom methods docs page.
  • Add :ref:s for each release on the changelog page so that they can be easily deeplinked.

EditPost set post title to "Untitled"

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

Allow custom Transport

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)

xmlrpc_client.DateTime incompatible with timetuple()

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.

custom_fields is not a list by default

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?

Page template not getting set.

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'}

WordPressBase __repr__ needs revision

In order to represent an Object the system do:

  1. Return a property string from WordPressChildClass.__str__
  2. Convert self.__str__ to ascii (str(self))
  3. Convert ascii self to utf-8 (.encode('UTF-8'))

Which IMHO is totally wrong because:

  • the majority of wordpress blogs defaults to UTF-8 data - and it can't be fully converted to ascii.
  • if converting to ascii, why bring back to utf-8?

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

Attaching thumbnail not working

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>```

Manage blog links

Hello,

it would be nice if we could add, edit and delete links from our blog link manager.

Best regards

Set options

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'

Evolution: visibility members to definition in WordPressPost class

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,

Convert REAMDE to rST

PyPI prefers rST formatting for displaying README/long description and GitHub will use rST just as well as it does Markdown.

WordpressPost incorrectly remaps `author` field

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...)

  • At the very least there should be an example in the documentation making this remap explicit.
  • In my opinion, a better solution is to have a consistent convention, aim for least surprise, and match the Wordpress documentation. It should be author.

NewCategory parent_id parameter wrong

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.

Create Documentation

Use Sphinx to create distinct documentation. Host it on either PyPI or RTFD.org.

Post methods should support all post types

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.

XML error

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!

UnicodeEncodeError

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)

my version of the fix

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

NameError: global name 'unicode' is not defined

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

How to properly work with dates?

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

Creating post of custom post type

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?

UnicodeDecodeError on printing comments with unicode in them

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') ?

Blog comments, and the 'date_created' field

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

Edit a post failed When user's role is Author

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))

parent_id not work

does not work attribute parent_id in class WordPressPage

after adding the page
parent is empty

<ProtocolError for site.wordpress.com/xmlrpc.php: 301 Moved Permanently>

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!

Support Python 3.x

If possible, add support Python 3.x, which is finally gaining some mainstream traction.

How to edit custom fields Wordpress with xmlrpc?

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))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.