我在heroku上托管了一个带有PostgreSQL数据库的Django Web应用程序。
我有一个文件试图读取数据库表作为pandas数据框。代码如下:
rom sqlalchemy import create_engine
import subprocess
proc = subprocess.Popen('heroku config:get DATABASE_URL -a moviesrsfinder', stdout=subprocess.PIPE, shell=True)
db_url = proc.stdout.read().decode('utf-8').strip()
engine = create_engine(db_url)
movies = pd.read_sql_query("SELECT * FROM movies", con=engine)
ratings = pd.read_sql_query("SELECT * FROM rating", con=engine)
该网络应用托管在此处:
https://moviesrsfinder.herokuapp.com/
在这里,电影和收视率是我需要阅读的两个数据库表。但是在heroku上部署后,它会引发以下错误:
ArgumentError at /
Could not parse rfc1738 URL from string ''
Request Method: GET
Request URL: https://moviesrsfinder.herokuapp.com/
Django Version: 2.0.6
Exception Type: ArgumentError
Exception Value:
Could not parse rfc1738 URL from string ''
Exception Location: /app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/url.py in _parse_rfc1738_args, line 254
Python Executable: /app/.heroku/python/bin/python
The local vars show an error in this line:
engine = create_engine(db_url)
如何解决此错误?请帮助我。