使用pythonwordpressxmlrp将图像库上载到wordpress

2024-10-06 12:40:31 发布

您现在位置:Python中文网/ 问答频道 /正文

好的,我已经用python创建了一个脚本,使用“pythonwordpress xmlrpc”包我可以做任何事情,除了上传多个图片到wordpress,然后添加到画廊。在

以下是我上载单个图像文件然后设置为功能图像的代码:

fileImg = urlopen('image_url')
imageName = fileImg.url.split('/')[-1]
imageType = mimetypes.guess_type(str(fileImg.url))[0]

data = {
    'name': imageName,
    'type': imageType,
}

data['bits'] = xmlrpc_client.Binary(fileImg.read())

response = client.call(media.UploadFile(data))
attachment_id = response['id']
widget.thumbnail = attachment_id

注意:我知道如何上载多个文件,但我不知道如何在产品库中添加这些图像。在


Tags: 图像脚本clientidurldataattachmentresponse