Hi,
First, whenever you make a change to environment variables or connection strings via portal please restart your webapp after clicking Apply.
Second, do you have your connection string under Settings -- Environment variables -- Connection strings tab, or App settings tab? If you have it under Connection strings tab with type PostgreSQL it will be injected into your app with prefix of POSTGRESQLCONNSTR_
For example, say you have a connection string in portal named MYCONNECTIONSTRING1. In your web app, it would show up as POSTGRESQLCONNSTR_MYCONNECTIONSTRING1 so in your python code you would use code similar to below:
conn_str = os.environ.get("POSTGRESQLCONNSTR_MYCONNECTIONSTRING1")
For troubleshooting purposes you may use SSH to connect to the worker and check the list of environment variables and their values. In the portal, navigate to your web app -- Development tools -- SSH blade, then click Go on right to launch session. At prompt you may type env to see list of variables.
Please click Accept Answer and upvote if the above was helpful.
Thanks.
-TP