I am using windows 10 (64-bit) and am following the course "Web Programming with python and Javascript" in CS50, in which i wanted to use my computer as a local host to store the table content. I am using PostgreSQL verison of 11.7 as the latest version doesn't seem to co-operate well.

I am running the below code and am still unsure on what my DATABASE_URL should be set to, where i am not trying to link any databases but only 2 tables named "flights" and "passengers".

import os

from flask import Flask,render_template , request
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():
    flights = db.execute("SELECT origin , desination , duration FROM flights").fetchall()
    for flight in flights:
        print(f"{flight.origin} to {flight.desination}, is {flight.duration} minuites")

These are the tables I have.

    List of relations
Schema |       Name        |   Type   |  Owner


 public | flights           | table    | postgres

 public | flights_id_seq    | sequence | postgres

 public | passengers        | table    | postgres

 public | passengers_id_seq | sequence | postgres

I am not sure on whether I should move these tables into a database and get some link or just try to link both tables, either way in which i'm unsure on how i should do it. Can it be done locally or should these tables be hosted online from websites such as Heroku.

Either way I've tried all possible methods and end up with the same error as shown,

    raise exc.ArgumentError(
sqlalchemy.exc.ArgumentError: Could not parse rfc1738 URL from string 'localhost'

It would be greatly appreciated if someone could help me ASAP. Thanks!


Since you're using Postgres, your DATABASE_URL environment variable should be in the form of postgresql://....

Since you're running the database on your own machine, the default host should be localhost with port 5432.

Setting DATABASE_URL to postgresql://localhost/<database name> should work!

  • Yes it did thanks!!
    – Najaaz
    May 15 '20 at 9:40
  • it shows following error after "set DATABASE_URL" ArgumentError( sqlalchemy.exc.ArgumentError: Could not parse rfc1738 URL from string ' postgresql://localhost:5432/newdb' May 22 '20 at 12:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .