我想用我的line連接到數據庫那裡去,卻一直出現錯誤。 下面代碼是在jupyter裡面測試寫也是按照 https://ithelp.ithome.com.tw/articles/10219773 的流程。
import os
import psycopg2
DATABASE_URL = os.popen('heroku config:get DATABASE_URL -a bot-all-day-long').read()[:-1]
conn = psycopg2.connect(DATABASE_URL, sslmode='require')
cursor = conn.cursor()
query = 'SELECT table_name FROM INFORMATION_SCHEMA.TABLES'
cursor.execute(query)
cursor.fetchone()
錯誤訊息是:
OperationalError Traceback (most recent call last)
<ipython-input-20-97d5072dff48> in <module>
4 DATABASE_URL = os.popen('heroku config:get DATABASE_URL -a bot-all-day-long').read()[:-1]
5
----> 6 conn = psycopg2.connect(DATABASE_URL, sslmode='require')
7 cursor = conn.cursor()
8
/srv/conda/envs/notebook/lib/python3.6/site-packages/psycopg2/__init__.py in connect(dsn, connection_factory, cursor_factory, **kwargs)
120
121 dsn = _ext.make_dsn(dsn, **kwargs)
--> 122 conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
123 if cursor_factory is not None:
124 conn.cursor_factory = cursor_factory
OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
不知道該怎麼辦。