title: How do I use sql alchemy create_engine with password that includes an @
body: <p>This works:</p>
  <pre><code>db = pyodbc.connect('driver={SQL Server Native Client 11.0}; server=172.30.0.194; database=db;uid=someuser; pwd=fancy@password')
  </code></pre>
  <p>This doesn't</p>
  <pre><code>cn_string = &quot;mssql+pyodbc://someuser:&amp;quot;fancy&amp;amp;password&amp;quot;@172.30.0.194/db?driver=SQL+Server+Native+Client+11.0&quot;
  return create_engine(cn_string)
  </code></pre>
  <p>This doesn't either:</p>
  <pre><code>driver = &quot;SQL Server Native Client 11.0&quot;
  server = &quot;192.30.0.194&quot;
  database = &quot;EPM_Dashboard&quot;
  uid = &quot;someuser&quot;
  pwd = &quot;fancy@password&quot;
  params = f'DRIVER={{{driver}}};SERVER={server};DATABASE={database};UID={uid};PWD={{{pwd}}};'
  
  connection_string = 'mssql+pyodbc:///?odbc_connect=%s' % urllib.parse.quote_plus(params)
  
  return create_engine(connection_string)
  </code></pre>
  <p>I get something like:</p>
  <p>Login timeout expired (0); [08001] [Microsoft][SQL Server Native Client 11.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. (53)</p>
  <p>which would be more believable if the pyodbc item failed.</p>
  <p>Here's another failure:</p>
  <pre><code>return create_engine(urllib.parse.quote_plus('driver={SQL Server Native Client 11.0}; server=172.30.0.194; database=EPM_Dashboard;uid=someuser; pwd=fancy@password'))
      
  </code></pre>
  <p>I'm sure there's a tricky character somewhere I'm missing.</p>
  <p>Here are some resources</p>
  <p><a href="https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-databases" rel="nofollow noreferrer">https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-databases</a></p>
  <p><a href="https://stackoverflow.com/questions/61431480/special-character-in-sql-password">Special character in SQL password</a></p>
  <p><a href="https://stackoverflow.com/questions/4493614/sqlalchemy-equivalent-of-pyodbc-connect-string-using-freetds">SqlAlchemy equivalent of pyodbc connect string using FreeTDS</a></p>