Skip to content

Fix 422 Unprocessable Entity when syncing to Mealie v3.12.0+#79

Open
TheZargs wants to merge 1 commit intoephes:mainfrom
TheZargs:main
Open

Fix 422 Unprocessable Entity when syncing to Mealie v3.12.0+#79
TheZargs wants to merge 1 commit intoephes:mainfrom
TheZargs:main

Conversation

@TheZargs
Copy link
Copy Markdown

Description:
Syncing recipes to Mealie fails with 422 Unprocessable Entity for all recipes when using Mealie v3.12.0 or newer.
Environment:

kptncook: 0.0.29
Mealie: v3.12.0

Root cause:
In mealie.py, several HTTP requests use data= instead of json= or content= with the correct Content-Type header. Newer versions of Mealie are stricter about content type validation and reject requests without Content-Type: application/json.
The affected lines in src/kptncook/mealie.py:

# _post_recipe_trunk_and_get_slug (~line 270)
# WRONG:
r = self.post("/recipes", data=json.dumps(data))
# FIXED:
r = self.post("/recipes", json=data)

# _scrape_image_for_recipe (~line 280)
# WRONG:
r = self.post(scrape_image_path, data=json_image_url)
# FIXED:
r = self.post(scrape_image_path, content=json_image_url, headers={"Content-Type": "application/json"})

# _create_item (~line 312)
# WRONG:
r = self.post(f"/{endpoint_name}", data=item.json())
# FIXED:
r = self.post(f"/{endpoint_name}", content=item.json(), headers={"Content-Type": "application/json"})

# _update_recipe (~line 361)
# WRONG:
r = self.put(recipe_detail_path, data=recipe.json())
# FIXED:
r = self.put(recipe_detail_path, content=recipe.json(), headers={"Content-Type": "application/json"})

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

Successfully merging this pull request may close these issues.

1 participant