Hi, @SC-2022 Welcome to Microsoft Q&A, Thanks for posting your question.
I Understand that you are unable to connect to PostgreSQL using Python using the script/sample code from the document.
I tried to connect using the above-mentioned code from the document and i was able to connect successfully please check the below code which might help you to fix if you have any issues in your code as the error seems to be in the code, also I want to check if you have followed all the prerequisites.
Regards
Geetha