简体   繁体   中英

Python Wordpress_XMLRPC NewComment Auth

Not fully understanding the Wordpress API for comments. I'm using the Wordpress_XMLRPC lib and so far I've tried variations of:

wp = Client(WPapilink, Wpusername, WPpassword)
comment = WordPressComment()
comment.content = CommentString
wp.call(comments.NewComment(PostID, comment))

The same settings are able to create a post but when I try adding comments I'm getting:

<class 'wordpress_xmlrpc.exceptions.InvalidCredentialsError'>

I know there is comment.user but what I can't figure out is if it wants an ID (I've tried 0 and 1), a username (tried the admin one) or will accept a string as the name (which would be the ideal).

I've tried going through the docs but I'm just not getting it. Next step is just inserting directly to the MySQL table if I can't figure this out. Would appreciate a nudge in the right direction.

Update: I was looking at the WordPress API and I can't see a reason for this. The author doesn't seem to matter for authentication. The auth it's using to create the post is with an admin login and it creates a post just fine so I'm not sure why it fails to add a comment.

Alright. Figured it out.

Comments were enabled for the site but they default to closed when the API posts them.

post.comment_status = 'open'

Set the comments as open when they were posted and it starts working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM