Python WordPress XML-RPC and Transport

 ̄綄美尐妖づ 提交于 2019-12-24 07:57:39

问题


I'm using python-wordpress-xmlrpc to create new posts on WordPress:

from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.posts import GetPosts, NewPost
from wordpress_xmlrpc.methods.users import GetUserInfo

from xmlrpc.client import Transport

class SpecialTransport(Transport):
    user_agent = 'Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31'

wp = Client('http://mysite.wordpress.com/xmlrpc.php', 'username', 'password', transport=SpecialTransport)

post = WordPressPost()
post.title = 'My new title'
post.content = 'This is the body of my new post.'

wp.call(NewPost(post))

This has been working fine with WordPress sites using http or https. But now I've come across a WordPress site on https where this does NOT work unless I remove the transport parameter i.e.

wp = Client('http://mysite.wordpress.com/xmlrpc.php', 'username', 'password')

What's the best way in my code to check if I need to include the transport parameter or not?

来源:https://stackoverflow.com/questions/46843100/python-wordpress-xml-rpc-and-transport

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!