mrhan1993 / Fooocus-API

FastAPI powered API for Fooocus
GNU General Public License v3.0
589 stars 159 forks source link

binascii.Error: Incorrect padding #378

Closed lascar1234 closed 4 months ago

lascar1234 commented 4 months ago

I'm getting error when running /v2/generation/image-prompt api call

v1 calls work fine.

full error stack

INFO: 127.0.0.1:60371 - "POST /v2/generation/image-prompt HTTP/1.1" 500 Internal Server Error ERROR: Exception in ASGI application Traceback (most recent call last): File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 426, in run_asgi result = await app( # type: ignore[func-returns-value] File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in call return await self.app(scope, receive, send) File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/fastapi/applications.py", line 1054, in call await super().call(scope, receive, send) File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/starlette/applications.py", line 123, in call await self.middleware_stack(scope, receive, send) File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/starlette/middleware/errors.py", line 186, in call raise exc File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/starlette/middleware/errors.py", line 164, in call await self.app(scope, receive, _send) File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/starlette/middleware/cors.py", line 93, in call await self.simple_response(scope, receive, send, request_headers=headers) File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/starlette/middleware/cors.py", line 148, in simple_response await self.app(scope, receive, send) File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 65, in call await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app raise exc File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/starlette/routing.py", line 756, in call await self.middleware_stack(scope, receive, send) File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/starlette/routing.py", line 776, in app await route.handle(scope, receive, send) File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/starlette/routing.py", line 297, in handle await self.app(scope, receive, send) File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/starlette/routing.py", line 77, in app await wrap_app_handling_exceptions(app, request)(scope, receive, send) File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app raise exc File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/starlette/routing.py", line 72, in app response = await func(request) File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/fastapi/routing.py", line 278, in app raw_response = await run_endpoint_function( File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/fastapi/routing.py", line 193, in run_endpoint_function return await run_in_threadpool(dependant.call, *values) File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/starlette/concurrency.py", line 42, in run_in_threadpool return await anyio.to_thread.run_sync(func, args) File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/anyio/to_thread.py", line 56, in run_sync return await get_async_backend().run_sync_in_worker_thread( File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 2177, in run_sync_in_worker_thread return await future File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 859, in run result = context.run(func, *args) File "/Users/main/Fooocus-API/fooocusapi/routes/generate_v2.py", line 179, in img_prompt req.input_image = base64_to_stream(req.input_image) File "/Users/main/Fooocus-API/fooocusapi/utils/img_utils.py", line 104, in base64_to_stream image_bytes = base64.b64decode(image) File "/Users/main/miniconda3/envs/fooocus/lib/python3.10/base64.py", line 87, in b64decode return binascii.a2b_base64(s) binascii.Error: Incorrect padding

lascar1234 commented 4 months ago

{ "prompt": "cat in a boat", "negative_prompt": "", "style_selections": [ "Fooocus V2", "Fooocus Enhance", "Fooocus Sharp" ], "performance_selection": "Speed", "aspect_ratios_selection": "1152*896", "image_number": 1, "image_seed": -1, "sharpness": 2, "guidance_scale": 4, "base_model_name": "juggernautXL_v8Rundiffusion.safetensors", "refiner_model_name": "None", "refiner_switch": 0.5, "loras": [ { "enabled": true, "model_name": "sd_xl_offset_example-lora_1.0.safetensors", "weight": 0.1 }, { "enabled": true, "model_name": "None", "weight": 1 }, { "enabled": true, "model_name": "None", "weight": 1 }, { "enabled": true, "model_name": "None", "weight": 1 }, { "enabled": true, "model_name": "None", "weight": 1 } ], "advanced_params": { "adaptive_cfg": 7, "adm_scaler_end": 0.3, "adm_scaler_negative": 0.8, "adm_scaler_positive": 1.5, "black_out_nsfw": false, "canny_high_threshold": 128, "canny_low_threshold": 64, "clip_skip": 2, "controlnet_softness": 0.25, "debugging_cn_preprocessor": false, "debugging_inpaint_preprocessor": false, "disable_intermediate_results": false, "disable_preview": false, "disable_seed_increment": false, "freeu_b1": 1.01, "freeu_b2": 1.02, "freeu_enabled": false, "freeu_s1": 0.99, "freeu_s2": 0.95, "inpaint_disable_initial_latent": false, "inpaint_engine": "v2.6", "inpaint_erode_or_dilate": 0, "inpaint_mask_upload_checkbox": false, "inpaint_respective_field": 1, "inpaint_strength": 1, "invert_mask_checkbox": false, "mixing_image_prompt_and_inpaint": false, "mixing_image_prompt_and_vary_upscale": false, "overwrite_height": -1, "overwrite_step": -1, "overwrite_switch": -1, "overwrite_upscale_strength": -1, "overwrite_vary_strength": -1, "overwrite_width": -1, "refiner_swap_method": "joint", "sampler_name": "dpmpp_2m_sde_gpu", "scheduler_name": "karras", "skipping_cn_preprocessor": false, "vae_name": "Default (model)" }, "save_meta": true, "meta_scheme": "fooocus", "save_extension": "png", "save_name": "", "read_wildcards_in_order": false, "require_base64": false, "async_process": false, "webhook_url": "", "input_image": "string", "input_mask": "", "inpaint_additional_prompt": "", "outpaint_selections": [], "outpaint_distance_left": -1, "outpaint_distance_right": -1, "outpaint_distance_top": -1, "outpaint_distance_bottom": -1, "image_prompts": [ { "cn_img": "string", "cn_stop": 0, "cn_weight": 0, "cn_type": "ImagePrompt" }, { "cn_img": "string", "cn_stop": 0, "cn_weight": 0, "cn_type": "ImagePrompt" } ] }

mrhan1993 commented 4 months ago

I will be check it later

lascar1234 commented 4 months ago

I have got it working now. Think the issue is with having both fooocus and Fooocus-API installed and copying over the config.txt file from fooocus to Fooocus-api I deleted them both and then only installed Fooocus-api, started it which downloaded all the models and it worked.

mrhan1993 commented 4 months ago

no, not because of this. When you pass an invalid base64 str for image, it will cause this