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

[BUG? DOCS?] - Ingredient parser UI fails with CORS errors when crf_test executable missing #4960

Open
5 of 6 tasks
CloCkWeRX opened this issue Jan 27, 2025 · 4 comments
Open
5 of 6 tasks
Labels
bug Something isn't working triage

Comments

@CloCkWeRX
Copy link

CloCkWeRX commented Jan 27, 2025

First Check

  • This is not a feature request.
  • I added a very descriptive title to this issue (title field is above this).
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the Mealie documentation, with the integrated search.
  • I already read the docs and didn't find an answer.
  • This issue can be replicated on the demo site (https://demo.mealie.io/).

What is the issue you are experiencing?

Image

Steps to Reproduce

New repo
task py
task ui
connect, authenticate successfully
import recipe (https://www.seriouseats.com/ham-and-cheese-sandwich-recipe-8605187)
settings -> ingredient amounts
parse

Please provide relevant logs

Browser:

ham-and-cheese-sandwich/ingredient-parser:1 Access to XMLHttpRequest at 'http://localhost:9000/api/parser/ingredients' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.Understand this errorAI
api-client.ts:16 Error: Network Error
    at createError (axios.js?v=343e1ca6:311:19)
    at XMLHttpRequest.handleError (axios.js?v=343e1ca6:579:18)
api-client.ts:15 
        
        
       POST http://localhost:9000/api/parser/ingredients net::ERR_FAILED 500 (Internal Server Error)

Mealie Version

mealie-next

Deployment

Other (please specify below)

Additional Deployment Details

No response

@CloCkWeRX CloCkWeRX added bug Something isn't working triage labels Jan 27, 2025
@CloCkWeRX
Copy link
Author

CloCkWeRX commented Jan 27, 2025

This bit, I'm really unclear on as if the CORS was wrong for the entire api endpoint; I wouldn't have expected recipe CRUD to have worked.

See vaguely similar to #4902
nuxt/nuxt#15332 possibly resolves it but is messy for a first run dev experience.

Edit:
Okay, normal API calls are fine due to the CORS header sent on the GET of the page.
Image
But that doesn't whitelist the ingredient endpoint for some reason.

@CloCkWeRX
Copy link
Author

Server logs:

[01/27/25 04:12:14] INFO     127.0.0.1:49978 - "OPTIONS /api/parser/ingredients HTTP/1.1" 200                                                                       httptools_impl.py:476
                    INFO     127.0.0.1:49998 - "POST /api/parser/ingredients HTTP/1.1" 500                                                                          httptools_impl.py:476
                    ERROR    Exception in ASGI application                                                                                                          httptools_impl.py:414
                             Traceback (most recent call last):                                                                                                                          
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/uvicorn/protocols/http/httptools_impl.py", line 409, in run_asgi                              
                                 result = await app(  # type: ignore[func-returns-value]                                                                                                 
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                 
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__                                    
                                 return await self.app(scope, receive, send)                                                                                                             
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                             
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__                                              
                                 await super().__call__(scope, receive, send)                                                                                                            
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/starlette/applications.py", line 113, in __call__                                             
                                 await self.middleware_stack(scope, receive, send)                                                                                                       
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 187, in __call__                                        
                                 raise exc                                                                                                                                               
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 165, in __call__                                        
                                 await self.app(scope, receive, _send)                                                                                                                   
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/starlette/middleware/cors.py", line 93, in __call__                                           
                                 await self.simple_response(scope, receive, send, request_headers=headers)                                                                               
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/starlette/middleware/cors.py", line 144, in simple_response                                   
                                 await self.app(scope, receive, send)                                                                                                                    
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/starlette/middleware/sessions.py", line 85, in __call__                                       
                                 await self.app(scope, receive, send_wrapper)                                                                                                            
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/starlette/middleware/gzip.py", line 20, in __call__                                           
                                 await responder(scope, receive, send)                                                                                                                   
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/starlette/middleware/gzip.py", line 39, in __call__                                           
                                 await self.app(scope, receive, self.send_with_gzip)                                                                                                     
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 62, in __call__                                     
                                 await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)                                                                                
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app                                     
                                 raise exc                                                                                                                                               
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app                                     
                                 await app(scope, receive, sender)                                                                                                                       
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/starlette/routing.py", line 715, in __call__                                                  
                                 await self.middleware_stack(scope, receive, send)                                                                                                       
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/starlette/routing.py", line 735, in app                                                       
                                 await route.handle(scope, receive, send)                                                                                                                
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/starlette/routing.py", line 288, in handle                                                    
                                 await self.app(scope, receive, send)                                                                                                                    
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/starlette/routing.py", line 76, in app                                                        
                                 await wrap_app_handling_exceptions(app, request)(scope, receive, send)                                                                                  
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app                                     
                                 raise exc                                                                                                                                               
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app                                     
                                 await app(scope, receive, sender)                                                                                                                       
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/starlette/routing.py", line 73, in app                                                        
                                 response = await f(request)                                                                                                                             
                                            ^^^^^^^^^^^^^^^^                                                                                                                             
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/fastapi/routing.py", line 301, in app                                                         
                                 raw_response = await run_endpoint_function(                                                                                                             
                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                             
                               File "/workspaces/mealie/.venv/lib/python3.12/site-packages/fastapi/routing.py", line 212, in run_endpoint_function                                       
                                 return await dependant.call(**values)                                                                                                                   
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                   
                               File "/workspaces/mealie/mealie/routes/parser/ingredient_parser.py", line 22, in parse_ingredients                                                        
                                 return await parser.parse(ingredients.ingredients)                                                                                                      
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                      
                               File "/workspaces/mealie/mealie/services/parser_services/ingredient_parser.py", line 88, in parse                                                         
                                 crf_models = crfpp.convert_list_to_crf_model(ingredients)                                                                                               
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                               
                               File "/workspaces/mealie/mealie/services/parser_services/crfpp/processor.py", line 62, in convert_list_to_crf_model                                       
                                 crf_output = _exec_crf_test([pre_process_string(x) for x in list_of_ingrdeint_text])                                                                    
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                    
                               File "/workspaces/mealie/mealie/services/parser_services/crfpp/processor.py", line 56, in _exec_crf_test                                                  
                                 return subprocess.check_output(["crf_test", "--verbose=1", "--model", MODEL_PATH, input_file.name]).decode(                                             
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                     
                               File "/usr/local/lib/python3.12/subprocess.py", line 466, in check_output                                                                                 
                                 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,                                                                                        
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                        
                               File "/usr/local/lib/python3.12/subprocess.py", line 548, in run                                                                                          
                                 with Popen(*popenargs, **kwargs) as process:                                                                                                            
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                        
                               File "/usr/local/lib/python3.12/subprocess.py", line 1026, in __init__                                                                                    
                                 self._execute_child(args, executable, preexec_fn, close_fds,                                                                                            
                               File "/usr/local/lib/python3.12/subprocess.py", line 1955, in _execute_child                                                                              
                                 raise child_exception_type(errno_num, err_msg, err_filename)                                                                                            
                             FileNotFoundError: [Errno 2] No such file or directory: 'crf_test'                   

@CloCkWeRX CloCkWeRX changed the title [BUG] - Access to XMLHttpRequest at 'http://localhost:9000/api/parser/ingredients' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. [BUG] - Ingredient parser UI fails with CORS errors when crf_test executable missing Jan 27, 2025
@CloCkWeRX
Copy link
Author

Discord suggests:

Image

Would be good if this was pulled automatically in setup; defaulted to a different parser; or raised a meaningful exception about the executable missing to the frontend a bit like the tests to with which crf_test

@CloCkWeRX
Copy link
Author

And annoyingly: crf++ not availableas a python package or easily installable.

@CloCkWeRX CloCkWeRX changed the title [BUG] - Ingredient parser UI fails with CORS errors when crf_test executable missing [BUG? DOCS?] - Ingredient parser UI fails with CORS errors when crf_test executable missing Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

1 participant