1
我想將ElephantSQL與Python連接起來。將ElephantSQL與Python連接
import os
import psycopg2
import urlparse
urlparse.uses_netloc.append("postgres")
url = urlparse.urlparse(os.environ["MY_DATABASE_URL"])
conn = psycopg2.connect(database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
,但我得到的錯誤:
Traceback (most recent call last): File "test.py", line 217, in url = urlparse.urlparse(os.environ["MY_DATABASE_URL"]) File "/usr/lib/python2.7/UserDict.py", line 23, in getitem raise KeyError(key) KeyError: 'MY_DATABASE_URL'
爲my_database_url我寫的網址從ElephantSQL(Postgres的:// my_username:MY_PASSWORD @ my_hostname/my_databasename)
我在做什麼錯?
該密鑰在您的環境中不存在 –