python-wordpress-xmlrpc
python-wordpress-xmlrpc copied to clipboard
<ProtocolError for blog.blog.com/xmlrpc.php: 403 Forbidden>
Just recently I have gotten this error for trying to connect to our Wordpress server:
wordpress_xmlrpc.exceptions.ServerConnectionError: <ProtocolError for blog.blog.com/xmlrpc.php: 403 Forbidden>
This seemed to be triggered by something, but we're not entirely sure what. It only applies to the certain IP address, so it seems like it has been blocked or something. I tried to whitelist that IP in Jetpack but that made no difference so I'm not really sure where the block is occurring. If you have any ideas, please let me know what might have caused this, and how it may be fixed! Thanks :)
This may be a problem with the website not trusting the user-agent. The default user-agent is Python-xmlrpc/[version number]
. Some hosts will automatically throw a 403 if your user-agent starts with the word "python".
If that is the root of the problem, you should be able to change the user-agent in the xmlrpc library.
from xmlrpc.client import Transport
import wordpress_xmlrpc
class SpecialTransport(Transport):
user_agent = 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0'
wordpress_client = wordpress_xmlrpc.Client('http://blog.blog.com/xmlrpc.php', 'normal_username', 'normal_password', transport=SpecialTransport())
This should work for Python 3 connecting to an unsecured (HTTP) site. If you're Python 2, change the first line to from xmlrpclib import Transport
. If your site is on HTTPS (it should be!), switch out Transport
for SafeTransport
.
from xmlrpc.client import Transport import wordpress_xmlrpc
class SpecialTransport(Transport): user_agent = 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0'
wordpress_client = wordpress_xmlrpc.Client('http://blog.blog.com/xmlrpc.php', 'normal_username', 'normal_password', transport=SpecialTransport())
That does not work for me. Again 403 error.