Unable to connect to atlas database, but able to connect to localhost:27017

I’m having issues connecting python flask api endpoints to shared host database. It throws an unknown error 500.
However, Interaction between flask api and localhost:27017 is working well.

In the attempt to connect to the shared host.
I used a connection string, which contains the db user login credentials.
Tried different libraries i.e. pymongo, flask_pymongo but they failed