Repository: stable-diffusion-webui
Issue: [Bug]: API Error:  /sdapi/v1/img2img returns error as 'str' object has no attribute 'convert'"
Labels: bug-report

### Is there an existing issue for this?

- [X] I have searched the existing issues and checked the recent builds/commits

### What happened?

I followed the steps to run img2img through swagger AP, but face this issue 'str' object has no attribute 'convert'".

{
  "init_images": [
    "<base64img>"
  ],
  "resize_mode": 0,
  "denoising_strength": 0.75,
  "image_cfg_scale": 0,
  "mask": "",
  "mask_blur": 4,
  "inpainting_fill": 0,
  "inpaint_full_res": true,
  "inpaint_full_res_padding": 0,
  "inpainting_mask_invert": 0,
  "initial_noise_multiplier": 0,
  "prompt": "cute white dog",
  "styles": [
    "string"
  ],
  "seed": -1,
  "subseed": -1,
  "subseed_strength": 0,
  "seed_resize_from_h": -1,
  "seed_resize_from_w": -1,
  "batch_size": 1,
  "n_iter": 1,
  "steps": 50,
  "cfg_scale": 7,
  "width": 512,
  "height": 512,
  "restore_faces": false,
  "tiling": false,
  "do_not_save_samples": false,
  "do_not_save_grid": false,
  "negative_prompt": "ugly",
  "eta": 0,
  "s_churn": 0,
  "s_tmax": 0,
  "s_tmin": 0,
  "s_noise": 1,
  "override_settings": {},
  "override_settings_restore_afterwards": true,
  "script_args": [],
  "sampler_index": "Euler",
  "include_init_images": false,
  "send_images": true,
  "save_images": false,
  "alwayson_scripts": {}
}



error:
{
  "error": "AttributeError",
  "detail": "",
  "body": "",
  "errors": "'str' object has no attribute 'convert'"
}


console:
API error: POST: https://9205563b314e0ba6a2.gradio.live/sdapi/v1/img2img {'error': 'AttributeError', 'detail': '', 'body': '', 'errors': "'str' object has no attribute 'convert'"}
Traceback (most recent call last):
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/streams/memory.py", line 94, in receive
    return self.receive_nowait()
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/streams/memory.py", line 89, in receive_nowait
    raise WouldBlock
anyio.WouldBlock

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 78, in call_next
    message = await recv_stream.receive()
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/streams/memory.py", line 114, in receive
    raise EndOfStream
anyio.EndOfStream

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/stable-diffusion-webui/modules/api/api.py", line 145, in exception_handling
    return await call_next(request)
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 84, in call_next
    raise app_exc
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 70, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 108, in __call__
    response = await self.dispatch_func(request, call_next)
  File "/home/ubuntu/stable-diffusion-webui/modules/api/api.py", line 110, in log_and_time
    res: Response = await call_next(req)
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 84, in call_next
    raise app_exc
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 70, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/gzip.py", line 24, in __call__
    await responder(scope, receive, send)
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/gzip.py", line 44, in __call__
    await self.app(scope, receive, self.send_with_gzip)
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/routing.py", line 66, in app
    response = await func(request)
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/routing.py", line 237, in app
    raw_response = await run_endpoint_function(
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/routing.py", line 165, in run_endpoint_function
    return await run_in_threadpool(dependant.call, **values)
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/concurrency.py", line 41, in run_in_threadpool
    return await anyio.to_thread.run_sync(func, *args)
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "/home/ubuntu/stable-diffusion-webui/modules/api/api.py", line 376, in img2imgapi
    processed = process_images(p)
  File "/home/ubuntu/stable-diffusion-webui/modules/processing.py", line 503, in process_images
    res = process_images_inner(p)
  File "/home/ubuntu/stable-diffusion-webui/modules/processing.py", line 594, in process_images_inner
    p.init(p.all_prompts, p.all_seeds, p.all_subseeds)
  File "/home/ubuntu/stable-diffusion-webui/modules/processing.py", line 977, in init
    image_mask = image_mask.convert('L')
AttributeError: 'str' object has no attribute 'convert'

![img2img-error500](https://user-images.githubusercontent.com/6793806/233624730-65e04f8c-dcd6-425d-aca0-f5df70f09c88.png)
[sd-api-img2img-ip-err2.txt](https://github.com/AUTOMATIC1111/stable-diffusion-webui/files/11295250/sd-api-img2img-ip-err2.txt)



### Steps to reproduce the problem

1. start websh

ubuntu@ip-
Textual inversion embeddings loaded(0):
Model loaded in 4.8s (load weights from disk: 0.3s, create model: 0.8s, apply weights to model: 1.2s, apply half(): 0.7s, load VAE: 1.1s, move model to device: 0.6s).
Running on local URL:  http://127.0.0.1:7860
Running on public URL: https://9205563b314e0ba6a2.gradio.live

This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces
Startup time: 15.2s (import torch: 1.0s, import gradio: 0.9s, import ldm: 0.6s, other imports: 0.7s, load scripts: 0.4s, load SD checkpoint: 5.0s, create ui: 0.2s, gradio launch: 6.2s, scripts app_started_callback: 0.1s).
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:07<00:00,  1.44s/it]
API error: POST: https://9205563b314e0ba6a2.gradio.live/sdapi/v1/img2img {'error': 'HTTPException', 'detail': 'Invalid encoded image', 'body': '', 'errors': ''}
API error: POST: https://9205563b314e0ba6a2.gradio.live/sdapi/v1/img2img {'error': 'HTTPException', 'detail': 'Sampler not found', 'body': '', 'errors': ''}
API error: POST: https://9205563b314e0ba6a2.gradio.live/sdapi/v1/img2img {'error': 'AttributeError', 'detail': '', 'body': '', 'errors': "'str' object has no attribute 'convert'"}


2. Use swagger to issue img2img generation using base64 img

### What should have happened?

Should have generated img

### Commit where the problem happens

np

### What platforms do you use to access the UI ?

_No response_

### What browsers do you use to access the UI ?

_No response_

### Command Line Arguments

```Shell
attached
```


### List of extensions

none

### Console logs

```Shell
attached
```


### Additional information

_No response_