Connecting to DB with SQLAlchemy
All of the imports are successful, but I get this error when trying to connect:
27 Replies
Everything was copy-pasted as shown into the
.env but with line breaks between variables as having everything in one line as shown on the page caused issues.
Using session pooling
This error also takes place using only psycopg2Is this the guide you were previously using https://supabase.com/docs/guides/troubleshooting/using-sqlalchemy-with-supabase-FUqebT since it seems here it reccomends either Using Transaction Pooler or Direct connection
Supabase Docs | Troubleshooting | Using SQLAlchemy with Supabase
Supabase is the Postgres development platform providing all the backend features you need to build a product.
Went through the connect menu. It says direct connections do not work on IPv4 networks

ahh okay, just confirming that was intentional. Is the error occuring only when you move the connection strong to the .env file, does it work if you inline it in the actual code?
Iām using the string in a Python file, only the variables are in .env
excluding any sensitive information how are you doing your create engine call
I switched to psycopg2, so I'm still working on it. I'll update you
I'm sure this is the password I used
Does your password have special characters?
Yes
You have to URL encode them if you are just setting up a string for the URL or possibly with some interfaces that don't encode for you.
It is better to not use them.
Then I should reset and use one without a special character
Depending on the character it could cause random issues as it messes up the whole URL after it.
Understood, thank you!
I will try that and see how it goes
It still gives me the same error, so I'll wait a bit and try again
I'm definitely using the right password and I'm still getting the same error'
No special characters
Anyways I think I have to use SQLAlchemy for my use case anyways, so let me try that again.
Wrong password error again
Are you seeing the password errors in the Postgres log also from the connections?
Are you sure you are going to this instance?
No, there are no errors
I can't say 100% but I think password errors would show up there if you were going to that instance.
Actually, I do see them in the Pooler logs
But they too show as "Ok" and not errors
Do they match your timing of trying?
Yes
I don't know if it's relevant that my RLS is disabled
I'd try from PSQL or the CLI to make sure your connection is working. I don't know anything about connecting with Python or SQLAlchmey.
If using the aws....com pooler connection make sure you user is postgres.projectid and not just postgres.
RLS is not involved with DB connections if you are Postgres user role.
Works just fine with the
psql command
I also tried removing the brackets around my password but it doesn't seem like it made a differenceYou definitely do not put brackets around the password in the url string.
Really?
I assumed there were because of how it's displayed
Let me remove them and let it sit for a bit
That is just their way of showing something to fill in.
It worked! š
I guess a lot of the confusion came from the .env file not updating immediately, and I also switched between SQLAlchemy and psycopg2 meaning I messed up some of the file.
I really appreciate all of the support