S
Supabase•2d ago
Mehdi

Connecting to DB with SQLAlchemy

All of the imports are successful, but I get this error when trying to connect:
FATAL: Authentication error, reason: "Invalid format for user or db_name"
FATAL: Authentication error, reason: "Invalid format for user or db_name"
27 Replies
Mehdi
MehdiOP•2d ago
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 psycopg2
ibrahim
ibrahim•23h ago
Is 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.
Mehdi
MehdiOP•23h ago
Went through the connect menu. It says direct connections do not work on IPv4 networks
No description
ibrahim
ibrahim•23h ago
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?
Mehdi
MehdiOP•22h ago
I’m using the string in a Python file, only the variables are in .env
ibrahim
ibrahim•22h ago
excluding any sensitive information how are you doing your create engine call
engine = create_engine(
"postgresql+psycopg2://me@localhost/mydb", pool_size=20, max_overflow=15
)
engine = create_engine(
"postgresql+psycopg2://me@localhost/mydb", pool_size=20, max_overflow=15
)
Mehdi
MehdiOP•13h ago
I switched to psycopg2, so I'm still working on it. I'll update you
Failed to connect: connection to server at "aws-0-us-west-2.pooler.supabase.com" (54.70.143.232), port 5432 failed: error received from server in SCRAM exchange: Wrong password
Failed to connect: connection to server at "aws-0-us-west-2.pooler.supabase.com" (54.70.143.232), port 5432 failed: error received from server in SCRAM exchange: Wrong password
I'm sure this is the password I used
garyaustin
garyaustin•13h ago
Does your password have special characters?
Mehdi
MehdiOP•13h ago
Yes
garyaustin
garyaustin•13h ago
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.
Mehdi
MehdiOP•13h ago
Then I should reset and use one without a special character
garyaustin
garyaustin•13h ago
Depending on the character it could cause random issues as it messes up the whole URL after it.
Mehdi
MehdiOP•8h ago
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
garyaustin
garyaustin•7h ago
Are you seeing the password errors in the Postgres log also from the connections? Are you sure you are going to this instance?
Mehdi
MehdiOP•7h ago
No, there are no errors
garyaustin
garyaustin•7h ago
I can't say 100% but I think password errors would show up there if you were going to that instance.
Mehdi
MehdiOP•7h ago
Actually, I do see them in the Pooler logs But they too show as "Ok" and not errors
garyaustin
garyaustin•7h ago
Do they match your timing of trying?
Mehdi
MehdiOP•7h ago
Yes I don't know if it's relevant that my RLS is disabled
garyaustin
garyaustin•7h ago
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.
Mehdi
MehdiOP•7h ago
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 difference
garyaustin
garyaustin•7h ago
You definitely do not put brackets around the password in the url string.
Mehdi
MehdiOP•7h ago
Really?
Mehdi
MehdiOP•7h ago
I assumed there were because of how it's displayed
No description
Mehdi
MehdiOP•7h ago
Let me remove them and let it sit for a bit
garyaustin
garyaustin•7h ago
That is just their way of showing something to fill in.
Mehdi
MehdiOP•6h ago
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

Did you find this page helpful?