How to access a python flask application written in vs code posit workbench

Hi All,
I'm quite new about posit world.
I need to create a Python flask app on posit workbench.
I did it using vscode on the workbench, but when I run I can't reach it:

if name == 'main':
# When running in Posit Workbench, apply ProxyFix middleware
# See: Tell Flask it is Behind a Proxy — Flask Documentation (2.2.x)
if 'RS_SERVER_URL' in os.environ and os.environ['RS_SERVER_URL']:
from werkzeug.middleware.proxy_fix import ProxyFix
app.wsgi_app = ProxyFix(app.wsgi_app, x_prefix=1)
app.run()

WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.

But I cannot access clicking on the link ...

What I'm doing wrong?

Thank you!

Hi @lmoraldo thank you for visiting and posting your question.

As you have found running web servers on Workbench is a little different than locally. Since you cannot access local host, Workbench proxies to a different URL which should be available in the Workbench extension for VS Code (access the extension on the left side toolbar). I will drop a screenshot below to show:

image

Thanks a very lot for quick reply!!!!!

This is what I expected, but it seems not working....

I think I'm missing something..

Here the screenshot:

Additional screenshot as the previous was with breakpoint that could cause confusion

Anyway the status is the same... no proxied servers are listed....

Very odd, I tried the same code on my end and I see it proxying. Could you try changing the /home to / and also let me know the command you are using to run the flask app (python -m flask run, etc.)

Good point.

Some steps forward:

If I use python -m flask run --debug the application starts and I can find the proxied server and able to access website!!! (but unable to debug)

If I use the launch.json config:


{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "app.py",
                "FLASK_DEBUG": "1"
            },
            "args": [
                "run"
            ],
            "jinja": true,
            "justMyCode": true
        },
        {
            "name": "Python: Module",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "justMyCode": true
        }
    ]
}

The app starts, but not able to see the proxied server and access to the website..... :sweat_smile:
So, i think it is something related to this launch.json (I did try some changes without success)

Do you have an idea on what could be?

Thanks!

Interesting, its good to see its working without the debugger. To dig deeper into the debug issue we will need more information from you. Could you or your server admin please file a support ticket: Posit Support - Posit Documentation

Attach the diagnostics explained on that page and I can provide background to our support team to dig in further.

In case others are looking for guidance here, the Posit Workbench User Guide has some details on how Flask or other python frameworks that require a proxy to access the running web server.

https://docs.posit.co/ide/server-pro/user/vs-code/guide/proxying-web-servers.html#flask

Thanks, I see documentation for couple of frameworks but some are blank like streamlit. Does it mean there is no option to do the same as for Dash, FastAPI or Flask.

Update: I relooked into Workbench extension as suggested by @tnederlof and I was able to find right url for streamlit.

Thank you.

Great that you were able to find a resolution! We have support as indicated for the following frameworks:

We have ensured the following server types can be proxied when using the extension in VS Code sessions. Other application types may work as expected.

However, most of them are able to be safely proxied behind the scenes and picked up by the Workbench extension. Certain frameworks require additional code to be added, so those specific examples are included in the docs.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.