1

使用 python 脚本在 WordPress 网站上发布文章。直到几天前,这一切都很好。现在,它的返回错误与 409 冲突有关。无法跟踪原因,因为我这边的代码没有变化。

Traceback (most recent call last):                                                                                                                                                                                               
  File "/home/vikas/anaconda3/lib/python3.7/site-packages/wordpress_xmlrpc/base.py", line 24, in __init__                                                                                                                        
    self.supported_methods = self.server.mt.supportedMethods()                                                                                                                                                                   
  File "/home/vikas/anaconda3/lib/python3.7/xmlrpc/client.py", line 1112, in __call__                                                                                                                                            
    return self.__send(self.__name, args)                                                                                                                                                                                        
  File "/home/vikas/anaconda3/lib/python3.7/xmlrpc/client.py", line 1452, in __request                                                                                                                                           
    verbose=self.__verbose                                                                                                                                                                                                       
  File "/home/vikas/anaconda3/lib/python3.7/xmlrpc/client.py", line 1154, in request                                                                                                                                             
    return self.single_request(host, handler, request_body, verbose)                                                                                                                                                             
  File "/home/vikas/anaconda3/lib/python3.7/xmlrpc/client.py", line 1187, in single_request                                                                                                                                      
    dict(resp.getheaders())                                                                                                                                                                                                      
xmlrpc.client.ProtocolError: <ProtocolError for www.indiandefencenews.co.in/xmlrpc.php: 409 Conflict>                                                                                                                            

During handling of the above exception, another exception occurred:                                                                                                                                                              

Traceback (most recent call last):                                                                                                                                                                                               
  File "t.py", line 16, in <module>                                                                                                                                                                                              
    client = Client('https://www.indiandefencenews.co.in/xmlrpc.php','user','password')                                                                                                             
  File "/home/vikas/anaconda3/lib/python3.7/site-packages/wordpress_xmlrpc/base.py", line 27, in __init__                                                                                                                        
    raise ServerConnectionError(repr(e))                                                                                                                                                                                         
wordpress_xmlrpc.exceptions.ServerConnectionError: <ProtocolError for www.indiandefencenews.co.in/xmlrpc.php: 409 Conflict>

我的代码是:

import urllib.request
import random
import csv
import os
import re

from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.compat import xmlrpc_client
from wordpress_xmlrpc.methods import media, posts


client = Client('https://www.website.com/xmlrpc.php','User','password')

 # prepare metadata
    data = {
        'name': 'picture.jpg',
        'type': 'image/jpeg',  # mimetype
        }
    with open(filename, 'rb') as img:
        data['bits'] = xmlrpc_client.Binary(img.read())
    response = client.call(media.UploadFile(data))
    attachment_id = response['id']

    post = WordPressPost()
    post.title = title
    post.content = text
    post.post_status = 'publish'
    post.thumbnail = attachment_id
    post.id = client.call(posts.NewPost(post))
    PID=post.id
    print ('Success')
    strn=str(num)
    url = url.replace(strn,'')
    print (strn)
    strn=int(num)+1
    url=url+str(strn)
    print (url)
4

0 回答 0