79751857

Date: 2025-08-31 15:40:48
Score: 0.5
Natty:
Report link

im with the same error and I've tried in many ways as possible... Here's my code "

class EdamamService:
    
    def __init__(self):
        self.api_key = settings.EDAMAM_API_KEY
        self.app_id = settings.EDAMAM_API_ID
        self.edamam_account_user = settings.EDAMAM_ACCOUNT_USER
        #--------------DEBUGGING PURPOSES----------------
        print(f"DEBUG: Loading App ID: '{self.app_id}'")
        print(f"DEBUG: Loading API Key: '{self.api_key}'")
        self.client = httpx.AsyncClient(
            base_url=settings.EDAMAM_API_URL, 
            params={
                "beta" : True,
                "app_key": self.api_key,
                "type": ["public"],
            }
        )
        
    async def get_meal_planner(self, data: MealPlanRequest) -> MealPlanResponse:
        """
        Get meal plan from Edamam API with comprehensive error handling
        """
        header = {
            'accept': 'application/json',
            'Content-Type': 'application/json',
            'Edamam-Account-User': self.edamam_account_user
        }
        try:
            # Convert Pydantic model to JSON
            request_data_dict = data.model_dump(mode='json', by_alias=True)
            
            response = await self.client.post(
                url=f"api/meal-planner/v1/{self.app_id}/select",
                json=request_data_dict,
                headers=header,
            )
            
            # Handle HTTP status errors
            response.raise_for_status()
            
            # Parse response JSON
            response_data = response.json()

" For some reason, it gives me still the 401 error, even if I use my email in edamam account user, even I create more api keys and try with them... I dont know what to do :/

Reasons:
  • Blacklisted phrase (1): I dont know what to do
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Andre Amorim