Some frequently used action about post on cnblogs:
import xmlrpclib
serviceUrl, appKey = 'http://www.cnblogs.com/yourusername/services/metaweblog.aspx', 'yourusername'
username, password = 'yourusername', 'yourpassword'
server = xmlrpclib.ServerProxy(serviceUrl)
res = server.metaWeblog.getRecentPosts('', username, password, 10)
print('no of posts: %d' % len(res))
print('list posts: %s' %res)
cat = server.metaWeblog.getCategories('', username, password)
print('no of categories: %d' %len(cat))
print('list categories: %s' %cat)
post = {'title':'My 4th Post', 'description':'some test text here\na new line', 'mt_keywords': 'test, demo'}
postid = server.metaWeblog.newPost('', username, password, post, True)
print('postid is: %s' % postid)
post = server.metaWeblog.getPost('3604635', username, password)
print('Get Post: %s' % post)
When publish new post, we often meet this error:
Traceback (most recent call last):
File "config.py", line 18, in <module>
postid = server.metaWeblog.newPost('', usr, passwd, post, True)
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 1473, in parse_response
return u.close()
File "/usr/lib/python2.7/xmlrpclib.py", line 793, in close
raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault 500: u'\u62b1\u6b49\uff01\u5df2\u8d85\u8fc7\u5f53\u65e5\u535a\u6587\u53d1\u5e03\u6570\u91cf100\u7bc7\u9650\u5236\uff01\u4eca\u5929\u65e0\u6cd5\u7ee7\u7eed\u53d1\u5e03\uff01'>
To see the error information, open a python shell, run following code
print(u'\u62b1\u6b49\uff01\u5df2\u8d85\u8fc7\u5f53\u65e5\u535a\u6587\u53d1\u5e03\u6570\u91cf100\u7bc7\u9650\u5236\uff01\u4eca\u5929\u65e0\u6cd5\u7ee7\u7eed\u53d1\u5e03\uff01')
Output:
抱歉!已超过当日博文发布数量100篇限制!今天无法继续发布!