Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'dataclasses._HAS_DEFAULT_FACTORY_CLASS'> #2133

Open
vaskers5 opened this issue Oct 21, 2024 · 6 comments

Comments

@vaskers5
Copy link

vaskers5 commented Oct 21, 2024

Here is code example:

import requests

gen_conf = {'enable_hr': False, 'denoising_strength': 1,
            'firstphase_width': 0, 'firstphase_height': 0,
            'hr_scale': 2, 'hr_upscaler': 'string', 'hr_second_pass_steps': 0,
            'hr_resize_x': 0, 'hr_resize_y': 0,
            'hr_sampler_name': 'string',
            'hr_prompt': '', 'hr_negative_prompt': '',
            '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, 'restore_faces': False, 'tiling': False, 'do_not_save_samples': False,
            'do_not_save_grid': False, 'eta': 0, 's_min_uncond': 5, 's_churn': 0, 's_tmax': None, 's_tmin': 0,
            's_noise': 1, 'override_settings_restore_afterwards': True, 'script_args': [], 'send_images': True, 'save_images': False, 'alwayson_scripts': {},
            'prompt': 'photo, closeup face portrait, female, (__lovescape-european__:1.4) , (Average:1.2) body BREAK female, (Blond:1.1) hair, (Straight:1.1) hairstyle BREAK female, (24 yo, young:1). (__lovescape-lips-2__:1), (__lovescape-noses-2__:1) nose, (__lovescape-faces-2__:1), (__lovescape-eyes-2__:1), (__lovescape-jaw-2__:1) jaw, (__lovescape-brows-2__:1) brows , (Fitness coach:1) occupation, ({tall|medium|short}:1) body height',
            'negative_prompt': 'nude, naked, topless', 'steps': 6, 'cfg_scale': 3, 'width': 768, 'height': 1024,
            'override_settings': {'sd_model_checkpoint': 'dreamshaperXL_v21TurboDPMSDE.safetensors', 'CLIP_stop_at_last_layers': 2},
            'sampler_index': 'DPM++ SDE', 'scheduler': 'Karras'}

url = "http://0.0.0.0:7862/sdapi/v1/txt2img"

from PIL import Image
import base64
import io


gen_conf_1 = gen_conf.copy()
gen_conf_1['override_settings']['sd_model_checkpoint'] = 'colorfulxl_v70'

response = requests.post(
                    url=url,
                    headers={"accept": "application/json"},
                    json=gen_conf,
                )
img = response.json()["images"][0].split(",", 1)[0]

# Decode the base64 string
img_data = base64.b64decode(img)

# Create a BytesIO object from the decoded data
img_buffer = io.BytesIO(img_data) 

# Create a PIL image from the BytesIO object
image = Image.open(img_buffer)

# Display the image
image.show()

here is error log:

`{
"name": "JSONDecodeError",
"message": "Expecting value: line 1 column 1 (char 0)",
"stack": "---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
File ~/anaconda3/envs/work/lib/python3.10/site-packages/requests/models.py:974, in Response.json(self, **kwargs)
973 try:
--> 974 return complexjson.loads(self.text, **kwargs)
975 except JSONDecodeError as e:
976 # Catch JSON-related errors and raise as requests.JSONDecodeError
977 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError

File ~/anaconda3/envs/work/lib/python3.10/json/init.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
343 if (cls is None and object_hook is None and
344 parse_int is None and parse_float is None and
345 parse_constant is None and object_pairs_hook is None and not kw):
--> 346 return _default_decoder.decode(s)
347 if cls is None:

File ~/anaconda3/envs/work/lib/python3.10/json/decoder.py:337, in JSONDecoder.decode(self, s, _w)
333 """Return the Python representation of s (a str instance
334 containing a JSON document).
335
336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()

File ~/anaconda3/envs/work/lib/python3.10/json/decoder.py:355, in JSONDecoder.raw_decode(self, s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
356 return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

JSONDecodeError Traceback (most recent call last)
Cell In[7], line 14
7 gen_conf_1['override_settings']['sd_model_checkpoint'] = 'colorfulxl_v70'
9 response = requests.post(
10 url=url,
11 headers={"accept": "application/json"},
12 json=gen_conf,
13 )
---> 14 img = response.json()["images"][0].split(",", 1)[0]
16 # Decode the base64 string
17 img_data = base64.b64decode(img)

File ~/anaconda3/envs/work/lib/python3.10/site-packages/requests/models.py:978, in Response.json(self, **kwargs)
974 return complexjson.loads(self.text, **kwargs)
975 except JSONDecodeError as e:
976 # Catch JSON-related errors and raise as requests.JSONDecodeError
977 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError
--> 978 raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

JSONDecodeError: Expecting value: line 1 column 1 (char 0)"
}
`

@vaskers5
Copy link
Author

working on fix, looks like simple pydantic bug

@rockiecxh
Copy link

encountered the same issue

@dermesut
Copy link

same here.
txt2img via api is broken now. img2img works.

@altoiddealer
Copy link
Contributor

altoiddealer commented Oct 21, 2024

Here to report the same issue.

Traceback (most recent call last):
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 396, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 70, in __call__
    return await self.app(scope, receive, send)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\fastapi\applications.py", line 1106, in __call__
    await super().__call__(scope, receive, send)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\starlette\applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\starlette\middleware\errors.py", line 184, in __call__
    raise exc
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\starlette\middleware\errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\gradio\route_utils.py", line 724, in __call__
    await self.app(scope, receive, send)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\starlette\middleware\exceptions.py", line 79, in __call__
    raise exc
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\starlette\middleware\exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 20, in __call__
    raise e
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 17, in __call__
    await self.app(scope, receive, send)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\starlette\routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\starlette\routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\starlette\routing.py", line 66, in app
    response = await func(request)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\fastapi\routing.py", line 292, in app
    content = await serialize_response(
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\fastapi\routing.py", line 160, in serialize_response    return field.serialize(
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\fastapi\_compat.py", line 147, in serialize
    return self._type_adapter.dump_python(
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\pydantic\type_adapter.py", line 142, in wrapped
    return func(self, *args, **kwargs)
  File "C:\0_SD\stable-diffusion-webui-forge\venv\lib\site-packages\pydantic\type_adapter.py", line 458, in dump_python
    return self.serializer.to_python(
pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'dataclasses._HAS_DEFAULT_FACTORY_CLASS'>

@hwoitke
Copy link

hwoitke commented Oct 21, 2024

Same issue. (calling the API via typescript client).

@vaskers5
Copy link
Author

#2138

I fixed it here, just a simple bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants