Python Forum
wordpress-python-xmlrpc. I can import 1 file. How do I import the entire folder?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
wordpress-python-xmlrpc. I can import 1 file. How do I import the entire folder?
#1
Im learning xmlrpc. I am able to import 1 image at a time. How do I import all images in a folder into a post?

from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.compat import xmlrpc_client
from wordpress_xmlrpc.methods import media, posts
from wordpress_xmlrpc import Client, WordPressPost
from wordpress_xmlrpc.methods.taxonomies import *
from wordpress_xmlrpc.methods.posts import *
from wordpress_xmlrpc.methods.users import *
from wordpress_xmlrpc.methods import *
wp_url = "http://192.168.0.105:80/wordpress/xmlrpc.php"
wp_username = 'admin'
wp_password = '#####'
wp = Client(wp_url, wp_username, wp_password)
filename = 'picture2.jpg'
data = {
'name': 'picture2.jpg',
'type': 'image/jpeg',  # mimetype
}
with open(filename, 'rb') as img:
 data ['bits'] = xmlrpc_client.Binary(img.read())

response = wp.call(media.UploadFile(data))
response == {
'id': 7,
'file': 'picture2.jpg',
'url': 'http://192.168.0.105/wordpress/wp-content/uploads/2018/07/04/picture2.jpg',
'type': 'image/jpeg',
}
attachment_id = response['id']
post = WordPressPost()
post.title = 'Pictures'
post.content = 'What a lovely picture today!'
post.post_status = 'publish'
post.thumbnail = attachment_id
post.id = wp.call(posts.NewPost(post))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ImportError: cannot import name 'NullHandler' from 'logging' sukanta80 0 630 Jul-28-2025, 03:26 PM
Last Post: sukanta80
  Dynamic Module Import Error DaddyMAN 3 1,641 Jun-20-2025, 12:07 AM
Last Post: Pedroski55
  ImportError: cannot import name 'Pyfhel' from 'Pyfhel' Anldra12 11 8,145 Jun-16-2025, 07:08 AM
Last Post: ItsTheGoose
  Error on import: SyntaxError: source code string cannot contain null bytes kirkwilliams2049 10 26,950 May-26-2025, 01:55 PM
Last Post: deanhystad
Question Import vs from x import Calab 1 786 May-15-2025, 04:09 PM
Last Post: snippsat
  I'm trying to import a dataset into a Jupyter Notebook Hisilat03 0 1,217 Mar-24-2025, 09:26 AM
Last Post: Hisilat03
  beginner doesn't understand import cimerio 3 1,164 Feb-12-2025, 05:02 PM
Last Post: cimerio
  Looping through each images in a give folder Python druva 1 2,577 Jan-01-2025, 08:46 AM
Last Post: Pedroski55
  How to write variable in a python file then import it in another python file? tatahuft 4 2,253 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  Python: How to import data from txt, instead of running the data from the code? Melcu54 1 1,352 Dec-13-2024, 06:50 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020