google / mesop

Rapidly build AI apps in Python
https://google.github.io/mesop/
Apache License 2.0
5.25k stars 249 forks source link

FileNotFoundError gpc.json #635

Open itsayellow opened 1 month ago

itsayellow commented 1 month ago

Describe the bug I've been trying to learn mesop. I have entered the "hello world" app (https://google.github.io/mesop/getting_started/quickstart/#hello-world-app) as mesop_test.py and run mesop mesop_test.py. When I navigate to the mesop-provided page on Firefox 128.0, I get a Traceback in my terminal, ending with:

  File "/<redacted>/.venv/lib/python3.12/site-packages/werkzeug/utils.py", line 428, in send_file
    stat = os.stat(path)
           ^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/<redacted>/.venv/lib/python3.12/site-packages/mesop/utils/../web/src/app/editor/web_package/.well-known/gpc.json'

This happens with both Python 3.11, 3.12, and with mesop 0.9.4 and 0.9.3

To Reproduce Steps to reproduce the behavior:

  1. Run the hello world app from https://google.github.io/mesop/getting_started/quickstart/#hello-world-app
  2. Open the page provided by mesop in Firefox

Expected behavior No errors in the Terminal.

Screenshots Actual Traceback (every time you invoke the page or reload the page):

E0718 15:17:44.755758 12918534144 app.py:838] Exception on /.well-known/gpc.json [GET]
Traceback (most recent call last):
  File "/<redacted>/.venv/lib/python3.12/site-packages/flask/app.py", line 1473, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<redacted>/.venv/lib/python3.12/site-packages/flask/app.py", line 882, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<redacted>/.venv/lib/python3.12/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/<redacted>/.venv/lib/python3.12/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<redacted>/.venv/lib/python3.12/site-packages/mesop/server/static_file_serving.py", line 112, in serve_file
    return send_file_compressed(
           ^^^^^^^^^^^^^^^^^^^^^
  File "/<redacted>/.venv/lib/python3.12/site-packages/mesop/server/static_file_serving.py", line 221, in send_file_compressed
    response = send_file(path)
               ^^^^^^^^^^^^^^^
  File "/<redacted>/.venv/lib/python3.12/site-packages/flask/helpers.py", line 499, in send_file
    return werkzeug.utils.send_file(  # type: ignore[return-value]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<redacted>/.venv/lib/python3.12/site-packages/werkzeug/utils.py", line 428, in send_file
    stat = os.stat(path)
           ^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/<redacted/.venv/lib/python3.12/site-packages/mesop/utils/../web/src/app/editor/web_package/.well-known/gpc.json'

Desktop System Info

Additional context Add any other context about the problem here.

itsayellow commented 1 month ago

Just tried this in Safari, and it does work as expected on Safari without a Traceback.

itsayellow commented 1 month ago

I found that this can be fixed so no error occurs if you do the following:

In .venv/lib/python3.12/site-packages/mesop/web/src/app/editor/web_package, add a subdirectory called .well-known, and inside a file called gpc.json that contains the following:

{
  "gpc": false,
  "lastUpdate": "2024-07-18"
}

At the very least, if it is not desirable to add this directory/file, it would be nice if mesop would not throw an error with a traceback when it is requested by a browser.

wwwillchen commented 1 month ago

Thanks for reporting this - looks like Firefox has a specific setting which sends a request for gpc.json - https://support.mozilla.org/en-US/kb/global-privacy-control.

Just to double-check, besides the terminal error message, the Mesop app is still working as expected?

itsayellow commented 1 month ago

Just to double-check, besides the terminal error message, the Mesop app is still working as expected?

Yes, it seems to be working fine in the browser otherwise. Just a bit alarming to be getting Tracebacks 🙂

itsayellow commented 1 month ago

Thanks for reporting this - looks like Firefox has a specific setting which sends a request for gpc.json - https://support.mozilla.org/en-US/kb/global-privacy-control.

Also I should note that I do NOT have that checkbox checked in my settings, so firefox seems to be requesting the GPC regardless of that setting.

wwwillchen commented 1 month ago

Got it, good to know. I think Mesop could send an empty 200 response, at least in development mode, just to avoid having a traceback. In prod, I'm not very familiar with gpc.json and we may need this to eventually be configurable by the Mesop app developer in terms of whether their app complies with this.

itsayellow commented 1 month ago

Reference: https://privacycg.github.io/gpc-spec/