Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
XMLRPC 'client' error
#1
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'
Reply
#2
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))
Reply
#3
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
Reply
#4
Error:
raise OSError("unsupported XML-RPC protocol")
I think this error occurs because of the XML-RPC is not running on target machine.
Reply
#5
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 ~ $ 
Reply
#6
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.
Reply
#7
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.
Reply
#8
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
Reply
#9
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'> >>>
Reply
#10
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"
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting "SSL client not supported by this Python installation" error prabirsarkar 0 963 Mar-13-2023, 05:01 PM
Last Post: prabirsarkar
  How to use xmlrpc from flrig? mamoman 3 1,113 Feb-10-2023, 06:25 PM
Last Post: Larz60+
  Error in Mysql Client when upgrading Django Abi 0 1,886 Sep-21-2020, 06:11 AM
Last Post: Abi
  Gnuradio python3 is not compatible python3 xmlrpc library How Can I Fix İt ? muratoznnnn 3 4,915 Nov-07-2019, 05:47 PM
Last Post: DeaD_EyE
  wordpress-python-xmlrpc. I can import 1 file. How do I import the entire folder? SamLearnsPython 0 3,270 Jul-05-2018, 06:21 AM
Last Post: SamLearnsPython
  xmlrpc.client, ServerProxy and null return thepurpleblob 0 3,051 Oct-26-2017, 10:26 AM
Last Post: thepurpleblob
  Error connecting to client rajeev1729 2 10,046 Sep-15-2017, 10:34 AM
Last Post: rajeev1729

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020