[API] pwg.images.addSimple endpoint incorrectly parses request JSON array #1472

Open
opened 2026-10-05 00:45:15 +02:00 by adam · 1 comment
Owner

I'm using python 3.9 and the requests package to upload images to my Piwigo gallery. I want to associate multiple tags with an image when I upload. My request code looks much like the following:

    tags = ["some  text", "more text"]
    headers = {'Accept': 'application/json'}
    params =  {'format' : 'json',  'method' : 'pwg.images.addSimple', 'Content-Type' : 'form-data'}
    files = {
        'image' : open(filename, "rb")
    }
    data = {
        'pwg_token' : pwg_token,
        'tags' : json.dumps(tags)
    }
        
    requests.post(piwigo_url, headers=headers, params=params, data = data, files=files)

Doing this leads to erroneous square brackets and quotation marks in the uploaded tag names. See the following image for an example of the incorrect tag names. The tag containing no quotation marks or square brackets is the format I am expecting for all the tags.

Screen Shot 2022-06-30 at 11 55 04 AM
I'm using python 3.9 and the requests package to upload images to my Piwigo gallery. I want to associate multiple tags with an image when I upload. My request code looks much like the following: ``` tags = ["some text", "more text"] headers = {'Accept': 'application/json'} params = {'format' : 'json', 'method' : 'pwg.images.addSimple', 'Content-Type' : 'form-data'} files = { 'image' : open(filename, "rb") } data = { 'pwg_token' : pwg_token, 'tags' : json.dumps(tags) } requests.post(piwigo_url, headers=headers, params=params, data = data, files=files) ``` Doing this leads to erroneous square brackets and quotation marks in the uploaded tag names. See the following image for an example of the incorrect tag names. The tag containing no quotation marks or square brackets is the format I am expecting for all the tags. <img width="1194" alt="Screen Shot 2022-06-30 at 11 55 04 AM" src="https://user-images.githubusercontent.com/108487316/176749619-9f4c48cd-53d1-4c96-accc-a92c62dc9f10.png"> <!-- github-sync-id:1290489725 -->
Author
Owner

Hi @is-unavco

Piwigo is not expecting the tags to be a JSON encoded string. It could be a possibility: first we check if it's a JSON string, if it is, Piwigo decodes it and it becomes an array as expected.

For now, you can either send an array (not JSON encoded) or a list of tag names separated by comma (as a simple string).

Hi @is-unavco Piwigo is not expecting the tags to be a JSON encoded string. It could be a possibility: first we check if it's a JSON string, if it is, Piwigo decodes it and it becomes an array as expected. For now, you can either send an array (not JSON encoded) or a list of tag names separated by comma (as a simple string). <!-- github-comment-id:1176282126 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/Piwigo#1472