ChrisGuest ChrisGuest - 10 months ago 80
Python Question

Escaping special characters in web2py database connection strings

I am using web2py to connect to a db with an 'at' sign in the password, eg 'P@sswd' .

db = DAL('mysql://user1:P@sswd@localhost/test')


This gets interpreted as a connection to host 'sswd@localhost' using password 'P'.

I have tried the obvious URL escaping technique but this failed:

db = DAL('mysql://user1:P%40sswd@localhost/test')


Is there a resource that explains the escaping conventions used in these URL style connection strings?

Answer Source

You should use decode_credentials option:

db = DAL('mysql://user1:P%40sswd@localhost/test', decode_credentials=True)