Configuring sqlalchemy engine with user containing “:”

215
January 01, 2021, at 10:10 AM

I am trying to configure an engine in sqlalchemy to connect with temporary credentials from an AWS IAM role using get_cluster_credentials api. When I do so this is the user I get 'IAM:user_rw'. Problem comes when I configure the engine string as

engine_string = "postgresql+pygresql://{user}:{password}@{endpoint}:{port}/{dbname}".format(
        user=cluster_creds['DbUser'],
        password=cluster_creds['DbPassword'],
        endpoint='big endpointstring',
        port=8192,
        dbname='small dbname')

I create the engine without errors but when running any query I get: FATAL: password authentication failed for user "IAM" Tested the user and pass in DataGrip it works so it seems evident sqlalchemy is getting the user just as "IAM" instead of 'IAM:user_rw'.

Do you know how can I force sqlalchemy to get the correct user?

Answer 1

I managed to solve the issue using urllib parse_quote in a similar fashion to what Gord is pointing. Final code

from urllib.parse import quote_plus
engine_string = "postgresql+pygresql://%s:%s@%s:%d/%s" % (
        quote_plus(user),
        quote_plus(passw),
        endpoint,
        port,
        dbname,
    )
Rent Charter Buses Company
READ ALSO
Transform is not applied on Embedded SVGs Chrome

Transform is not applied on Embedded SVGs Chrome

I am new to using SVGs, but everything was fine until I tried my code on chrome and found that it doesn't work properly, all transform attributes are neglectedFirefox gets it done as expected

40
JavaScript Memory Model with Process Memory model

JavaScript Memory Model with Process Memory model

I'm studying Process Memory model and got curious with JavaScript's memory model

162
mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python 'list' cannot be converted to a MySQL type

mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python 'list' cannot be converted to a MySQL type

I am attempting to insert a value into my table where it selects an ID by matching it with its name and inserting it into a second tableHowever when I print out the selected value it prints [(1,)] which is classed as a list

380
jQuery ajax response time

jQuery ajax response time

I'm using a simple Ajax get method on local machine that providing to empty function in my server-side laravel code, and observe from browser network that response is returned randomly in from 250-500ms

164