title: Python SQLAlchemy authentication failed for user
body: <p>I try to connect a PostgreSQL database with SQLAlchemy.</p>
  
  <p>I created a new role like that.First of all I logged into the postgres account with the command</p>
  
  <pre><code>sudo -i -u postgres
  </code></pre>
  
  <p>Next, issued the command:</p>
  
  <pre><code>createuser --interactive
  </code></pre>
  
  <p>Also I created a new user account for database users.</p>
  
  <pre><code>sudo adduser veritabani
  </code></pre>
  
  <p>Once I've completed this process, I used this command to access the PostgreSQL prompt</p>
  
  <pre><code>sudo -i -u veritabani
  psql -d havalimani
  </code></pre>
  
  <p>Also I executed an SQL stament which works fine.</p>
  
  <pre><code>SELECT * FROM uçuşlar;
  </code></pre>
  
  <p>On the other hand I'd like to access database using Python and SQLAlchemy. I have a code like that :</p>
  
  <pre><code>import os
  
  from sqlalchemy import create_engine
  from sqlalchemy.orm import scoped_session, sessionmaker
  
  engine = create_engine(os.getenv("DATABASE_URL"))
  db = scoped_session(sessionmaker(bind=engine))
  
  def main():
      print (os.getenv("DATABASE_URL"))
  
      flights =  db.execute("SELECT kalkış, varış, süre FROM uçuşlar")
      for flight in flights:
          print(f"{flight.kalkış} dan {flight.varış} a, {flight.süre} dakika")
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>I use this statement to give DATABASE_URL an initial value;</p>
  
  <pre><code>export DATABASE_URL="postgresql://localhost/havalimani?user=veritabani&amp;password=pwd"
  </code></pre>
  
  <p>But when I run Python program it gives an error like that :</p>
  
  <pre><code>FATAL:  password authentication failed for user "veritabani" 
  (Background on this error at: http://sqlalche.me/e/e3q8)
  </code></pre>