'Python Image Url Extraction
I am uploading an image to a wordpress site. How can I get the url of the image? The library is at this link. I am sharing the codes. https://python-wordpress-xmlrpc.readthedocs.io/en/latest/ref/methods.html#wordpress_xmlrpc.methods.demo.SayHello
filename = 'C:\\Users\\Image_1.jpg'
prepare metadata
data = {
'name': 'Image_1.jpg',
'type': 'image/jpeg', # mimetype
}
read the binary file and let the XMLRPC library encode it into base64
with open(filename, 'rb') as img: data['bits'] = xmlrpc_client.Binary(img.read())
response = client.call(media.UploadFile(data))
attachment_id = response['id']
Solution 1:[1]
Have a look at the docs you linked: https://python-wordpress-xmlrpc.readthedocs.io/en/latest/ref/methods.html#wordpress_xmlrpc.methods.media.UploadFile
it says that the media.UploadFile method:
Returns: dict with keys id, file (filename), url (public URL), and type (MIME-type).
so you should be able to get the url of uploaded image in response["url"]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Anentropic |
