Posts: 19
Threads: 7
Joined: Jul 2018
Jul-02-2018, 11:58 AM
(This post was last modified: Jul-02-2018, 12:02 PM by buran.)
I'm trying to create a wordpress post through XMLRPC but getting this error
(env) sam@sam-H81M-S ~ $ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 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_url = '``http://localhost/wordpress``'
>>> wp_username = 'admin'
>>> wp_password = ' ######## '
>>> post = WordPressPost()
>>> post.title = 'My Post'
>>> post.content = 'This is content'
>>> post.id = client.call(posts.NewPost(post)) Error: Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'client' is not defined
When I use Client I get this error instead
Error: Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: call() missing 1 required positional argument: 'method'
Posts: 333
Threads: 4
Joined: Jun 2018
Jul-02-2018, 01:05 PM
(This post was last modified: Jul-02-2018, 01:05 PM by gontajones.)
I think you have to create a Client object and then use the call() method.
wp_url = '``http://localhost/wordpress``'
wp_username = 'admin'
wp_password = ' ######## '
wp = Client(wp_url, wp_username, wp_password)
post = WordPressPost()
post.title = 'My Post'
post.content = 'This is content'
post.id = 1
wp.call(WordPressPost(post))
Posts: 19
Threads: 7
Joined: Jul 2018
Getting this error
Error: wp = Client(wp_url, wp_username, wp_password)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/sam/env/lib/python3.5/site-packages/wordpress_xmlrpc/base.py", line 23, in __init__
self.server = xmlrpc_client.ServerProxy(url, allow_none=True, transport=transport)
File "/usr/lib/python3.5/xmlrpc/client.py", line 1398, in __init__
raise OSError("unsupported XML-RPC protocol")
OSError: unsupported XML-RPC protocol
Posts: 333
Threads: 4
Joined: Jun 2018
Error: raise OSError("unsupported XML-RPC protocol")
I think this error occurs because of the XML-RPC is not running on target machine.
Posts: 19
Threads: 7
Joined: Jul 2018
But it's telling me its already installed?
sam@sam-H81M-S ~ $ python3 -m venv env
sam@sam-H81M-S ~ $ source ./env/bin/activate
(env) sam@sam-H81M-S ~ $ pip install python-wordpress-xmlrpc
Requirement already satisfied (use --upgrade to upgrade): python-wordpress-xmlrpc in ./env/lib/python3.5/site-packages
You are using pip version 8.1.1, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(env) sam@sam-H81M-S ~ $
Posts: 333
Threads: 4
Joined: Jun 2018
Jul-02-2018, 07:14 PM
(This post was last modified: Jul-02-2018, 07:16 PM by gontajones.)
Have you started the XML-RPC server on your server (localhost)? Plugin xml-rpc-modernization
From Overview
Quote:Create an instance of the Client class with the URL of the WordPress XML-RPC endpoint and user credentials. Then pass an XmlrpcMethod object into its call method to execute the remote call and return the result.
You'll have to address wp_url to something like http://localhost:port/xmlrpc.php .
Posts: 19
Threads: 7
Joined: Jul 2018
Both the XMLRPC documentation page and Wordpress documentation page state
Quote:XML-RPC functionality is turned on by default since WordPress 3.5. In previous versions of WordPress, XML-RPC was user enabled
This is the output for localhost:port/wordpress/xmlrpc.php
Quote:XML-RPC server accepts POST requests only.
Posts: 333
Threads: 4
Joined: Jun 2018
That's good.
Have you tried with this URL?
wp_url = "http://localhost:PORT_NUM/wordpress/xmlrpc.php"
wp_username = 'admin'
wp_password = ' ######## '
wp = Client(wp_url, wp_username, wp_password)
post = WordPressPost()
post.title = 'My Post'
post.content = 'This is content'
post.id = 1
wp.call(WordPressPost(post)) Check these Several Examples
Posts: 19
Threads: 7
Joined: Jul 2018
Jul-03-2018, 01:39 PM
(This post was last modified: Jul-03-2018, 01:39 PM by SamLearnsPython.)
Nope still didnt work
(env) sam@sam-H81M-S ~ $ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 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_url = "http://localhost:PORT NUM/wordpress/xmlrpc.php"
>>> wp_username = 'admin'
>>> wp_password = '######'
>>> wp = Client(wp_url, wp_username, wp_password) Error: Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/sam/env/lib/python3.5/site-packages/wordpress_xmlrpc/base.py", line 24, in __init__
self.supported_methods = self.server.mt.supportedMethods()
File "/usr/lib/python3.5/xmlrpc/client.py", line 1092, in __call__
return self.__send(self.__name, args)
File "/usr/lib/python3.5/xmlrpc/client.py", line 1432, in __request
verbose=self.__verbose
File "/usr/lib/python3.5/xmlrpc/client.py", line 1134, in request
return self.single_request(host, handler, request_body, verbose)
File "/usr/lib/python3.5/xmlrpc/client.py", line 1150, in single_request
return self.parse_response(resp)
File "/usr/lib/python3.5/xmlrpc/client.py", line 1322, in parse_response
return u.close()
File "/usr/lib/python3.5/xmlrpc/client.py", line 655, in close
raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault -32700: 'parse error. not well formed'>
>>>
Posts: 333
Threads: 4
Joined: Jun 2018
You need to put your port number in the URL.
How did you install the wordpress on your machine?
Test with the HTTP standard port:
>>> wp_url = "http://localhost:80/wordpress/xmlrpc.php" Or
>>> wp_url = "http://localhost/wordpress/xmlrpc.php"
|