OSError: cannot write mode RGBA as JPEG

What is your code? When I tried this:

@anvil.server.callable
def resize(file):
  # Convert the 'file' Media object into a Pillow Image
  img = Image.open(io.BytesIO(file.get_bytes()))
  
  # Resize the image to the required size
  img = img.resize((800,600))
  img = img.convert("RGB")
  # Convert the Pillow Image into an Anvil Media object and return it
  bs = io.BytesIO()
  img.save(bs, format="RGB")
  return anvil.BlobMedia("image/RGB", bs.getvalue(), name="Name")

I got this error:

KeyError: ‘RGB’ at /usr/local/lib/python3.7/site-packages/PIL/Image.py, line 2091 called from [ServerModule1, line 19](javascript:void(0)) called from [Form1, line 14](javascript:void(0))