# Keep getting error '400' status code

**URL:** <https://discuss.huggingface.co/t/keep-getting-error-400-status-code/75263>\
**Category:** Amazon SageMaker\
**Created:** [February 29, 2024, 4:18am UTC](https://discuss.huggingface.co/t/keep-getting-error-400-status-code/75263 "2024-02-29T04:18:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nexusai3060](https://avatars.discourse-cdn.com/v4/letter/n/eb9ed0/32.png) [@nexusai3060](https://discuss.huggingface.co/u/nexusai3060)\
**Post date:** [February 29, 2024, 4:18am UTC](https://discuss.huggingface.co/t/keep-getting-error-400-status-code/75263/1 "2024-02-29T04:18:37Z")

</div>

I keep running into this error:

> ModelError Traceback (most recent call last)  
> Cell In[13], line 46  
> 43 serialized\_payload = json.dumps(payload) # Serialize the payload to JSON format  
> 45 # Make API call  
> —\> 46 response = client.invoke\_endpoint(  
> 47 EndpointName=endpoint\_name,  
> 48 Body=serialized\_payload,  
> 49 ContentType=‘application/json’ # Specify the format of the payload  
> 50 )  
> 52 response\_payload = json.loads(response[‘Body’].read().decode(“utf-8”))  
> 54 end\_time = time.time()
> 
> File /opt/conda/lib/python3.10/site-packages/botocore/client.py:535, in ClientCreator.\_create\_api\_method..\_api\_call(self, \*args, \*\*kwargs)  
> 531 raise TypeError(  
> 532 f"{py\_operation\_name}() only accepts keyword arguments."  
> 533 )  
> 534 # The “self” in this scope is referring to the BaseClient.  
> → 535 return self.\_make\_api\_call(operation\_name, kwargs)
> 
> File /opt/conda/lib/python3.10/site-packages/botocore/client.py:980, in BaseClient.\_make\_api\_call(self, operation\_name, api\_params)  
> 978 error\_code = parsed\_response.get(“Error”, {}).get(“Code”)  
> 979 error\_class = self.exceptions.from\_code(error\_code)  
> → 980 raise error\_class(parsed\_response, operation\_name)  
> 981 else:  
> 982 return parsed\_response
> 
> ModelError: An error occurred (ModelError) when calling the InvokeEndpoint operation: Received client error (400) from primary with message "{  
> “code”: 400,  
> “type”: “InternalServerException”,  
> “message”: “\u0027NoneType\u0027 object has no attribute \u0027startswith\u0027”  
> }

This is my model’s inference script:

> %%writefile code/inference.py  
> import base64  
> import torch  
> from io import BytesIO  
> from diffusers import StableDiffusionPipeline
> 
> def model\_fn(model\_dir):  
> # Load stable diffusion and move it to the GPU  
> pipe = StableDiffusionPipeline.from\_pretrained(model\_dir, torch\_dtype=torch.float16)  
> pipe = pipe.to(“cuda”)
> 
> ```
> return pipe
> 
> ```
> 
> def predict\_fn(data, pipe):
> 
> ```
> # get prompt & parameters
> prompt = data.pop("inputs", data)
> # set valid HP for stable diffusion
> num_inference_steps = data.pop("num_inference_steps", 50)
> guidance_scale = data.pop("guidance_scale", 7.5)
> num_images_per_prompt = data.pop("num_images_per_prompt", 4)
> 
> # run generation with parameters
> generated_images = pipe(
> prompt,
> num_inference_steps=num_inference_steps,
> guidance_scale=guidance_scale,
> num_images_per_prompt=num_images_per_prompt,
> )["images"]
> 
> # create response
> encoded_images = []
> for image in generated_images:
> buffered = BytesIO()
> image.save(buffered, format="JPEG")
> encoded_images.append(base64.b64encode(buffered.getvalue()).decode())
> 
> # create response
> return {"generated_images": encoded_images}
> 
> ```

Does anyone know how to fix this?
