[Python] Sending PIL Image over request in Python

Discussão em 'Python' iniciado por Stack, Setembro 5, 2025.

  1. Stack

    Stack Membro Participativo

    I have created a PIL Image and I want to send it to a server over requests.

    My code looks like this, but I am not able to get it working as I get no errors.

    import requests
    from PIL import Image
    from io import BytesIO

    img = Image.new('RGB', (25, 25), color = (120, 120, 20))
    byte_io = BytesIO()
    img.save(byte_io, 'png')
    byte_io.seek(0)

    requests.post(
    url('/media/upload'),
    files={
    'files[]': (
    '1.png',
    byte_io,
    'multipart/form-data'
    )
    },
    )


    print files gives me {'files[]': ('1.png', <_io.BytesIO object at 0x105b69290>, 'multipart/form-data')} and it does not error out.

    Continue reading...

Compartilhe esta Página