Skip to content
Advertisement

Python: urllib.parse.quote_plus and edit string

I need to add a wild card to a urllib.parse.quote_plus command but I am unclear how to.

When I execute the following on my flask server, I get the following error:

ValueError: unsupported format character 'D' (0x44) at index 8

How might I add a wildcard in here to accept an object?

user_email = 'my_email@xd.com'
params = urllib.parse.quote_plus("Driver={ODBC Driver 17 for SQL Server};Server=tcp:dbhere.database.windows.net,1433;Database=dbhere;Uid=%s;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=15;Authentication=ActiveDirectoryIntegrated")
params.replace('%s;', user_email)
# result
'Driver%3D%7BODBC+Driver+17+for+SQL+Server%7D%3BServer%3Dtcp%3Adbhere.database.windows.net%2C1433%3BDatabase%3Ddbhere%3BUid%3D%25s%3BEncrypt%3Dyes%3BTrustServerCertificate%3Dno%3BConnection+Timeout%3D15%3BAuthentication%3DActiveDirectoryIntegrated'

Advertisement

Answer

i think you should do the replacing first

user_email = 'my_email@xd.com'
params = urllib.parse.quote_plus("stuff;Uid=%s;stuff" % user_email)

or

params = urllib.parse.quote_plus(f"stuff;Uid={user_email};stuff")
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement