1

I have looked at various solutions and am familiar with using the \ as an escape character. Im in a situation where I need to pass credentials over pyodbc and in making my connection string I need to pass credentials, unfortunately my username is in the format domain\username . I am continually getting errors because the literal string passed to SQL server is domain\username. I have seen a similar question on here trying to figure this out for url requests. I tried implementing it and I end up with the same error once the actual credentials are decoded. I've tried all kinds of string and raw string tricks best I can get is either '\ ' (with space behind it) or '\\' being literally passed to SQL Server. Any ideas?

#username and password is an argument passed from the console, lets just focus on username issue

username = bytes(sys.argv, 'utf8')
credentials = base64.b64encode(usename, altchars = bytes('\ ', 'utf8') )

cnxnstrng = f'''Driver={SQL Server};
Server=server;
Database=database};
UID={base64.b64decode(credentials)};
PWD=password'''
mitch
  • 379
  • 1
  • 3
  • 14
  • It looks like you're making things a lot more difficult than they need to be. Backslash is not a "special" character that needs escaping in an ODBC connection string, so `r'domain\username'` should "just work". Please [edit] your question to indicate what specific errors you are getting. – Gord Thompson Aug 14 '19 at 20:08
  • 1
    Yeah I thought that, but I am getting a login error [28000] where it say 'failed to login for user domain\\username' Im thinking that extra \ that's is being passed is causing this, as the actual username is domain/username not domain\\username. – mitch Aug 14 '19 at 20:39
  • That's probably just a display artifact similar to what you will see if you do `print(repr(r'hello\world'))` – Gord Thompson Aug 14 '19 at 21:15

0 Answers0