来自本地 OS X Python 脚本的 OpenS(QL)hift PostgreSQL 连接
PostgreSQL connection WITH OpenS(QL)hift from a Local OS X Python Script
我正在尝试从 OS X Python 脚本连接到 OpenShift。 OpenShift 确实有效。但是,我正在寻找 python 的 "easy" 方式,而无需将额外的 PGSQL 库下载到 OS X。谢谢!
问题:为此使用的正确域名是什么??我们能否在不导入 python 的情况下保持简单?
我不想使用任何额外的库。
我遇到的主要问题是 pgsql.connect(dbname = 'orion', host = '127.7.74.2:5432', #'localhost', port = 5432, user = 'earthling', 密码 = 'extraterrestrial')
这是代码文件的样子"pgsql.py"...
# PostgreSQL Client:
# http://www.postgresql.org/docs/current/static/reference-client.html
# PostgreSQL Server:
# http://www.postgresql.org/docs/current/static/runtime.html
# PostgreSQL Commands:
# http://www.postgresql.org/docs/current/static/reference.html
# PostgreSQL Data Types:
# http://www.postgresql.org/docs/current/static/datatype.html
conn = psycopg2.connect(dbname = 'orion',
host = '127.7.74.2:5432', #'localhost',
port = 5432,
user = 'earthling',
password = 'extraterrestrial')
sql = conn.cursor()
def CREATE_TABLE(table, text):
sql.execute("CREATE TABLE " + table + " (" + text + ");")
def INSERT(table, url, text):
#date = datetime.date.today()
date = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
print date
query = "INSERT INTO " + table + " (url, text, date) VALUES (%s, %s, %s);"
params = (url, text, date,)
sql.execute(query, params)
def SELECT(table, url):
query = "SELECT * FROM " + table + " WHERE url = %s;"
sql.execute(query, (url,))
def QUERY(text):
sql.execute(text)
INSERT("main", "www.whoi.edu", "test")
print SELECT("main", "www.whoi.edu")
感谢您的帮助!
问题:这应该相当简单并且不需要 psycopg2?
能否分享一下您在尝试连接时遇到的问题?
就使用 Python 而言,我们必须使用 cx_oracle 连接到我们的 oracle 表,所以我希望您必须使用 psycopg2 连接 PostGresQL因为没有库可能就没有本机功能。
不过我刚刚读到你在 OS X 上,所以它可能完全不同。用 OS X 标记您的问题,看看这是否有助于更好地获取答案。
除了客户端库问题之外,您需要使用端口转发将 OpenShift 内部的 PostgreSQL 数据库公开到您的本地计算机。 OpenShift 内部的 PostgreSQL 服务的 IP 地址不会对外可见。请参阅有关使用 OpenShift 进行端口转发的教程,网址为:
我想我将使用本地 table(迷你哈希table),这比连接到远程数据库更快。
但是,另一个 SOLUTION 是(我相信使用 OpenShift 可能可行)从 OpenShift 创建 ROUTE 外部路径。如果 OpenShift 将来支持它,它可能会是这样的。安全性可能类似于 Dropbox 样式连接到 PostgreSQL 服务器。希望这些设置对某人有所帮助?但是,除非进行其他一些管理设置,否则它可能无法工作??!但是,但是,将来可能会有什么用? #local-made-up-mini-table-sql
我正在尝试从 OS X Python 脚本连接到 OpenShift。 OpenShift 确实有效。但是,我正在寻找 python 的 "easy" 方式,而无需将额外的 PGSQL 库下载到 OS X。谢谢!
问题:为此使用的正确域名是什么??我们能否在不导入 python 的情况下保持简单?
我不想使用任何额外的库。
我遇到的主要问题是 pgsql.connect(dbname = 'orion', host = '127.7.74.2:5432', #'localhost', port = 5432, user = 'earthling', 密码 = 'extraterrestrial')
这是代码文件的样子"pgsql.py"...
# PostgreSQL Client:
# http://www.postgresql.org/docs/current/static/reference-client.html
# PostgreSQL Server:
# http://www.postgresql.org/docs/current/static/runtime.html
# PostgreSQL Commands:
# http://www.postgresql.org/docs/current/static/reference.html
# PostgreSQL Data Types:
# http://www.postgresql.org/docs/current/static/datatype.html
conn = psycopg2.connect(dbname = 'orion',
host = '127.7.74.2:5432', #'localhost',
port = 5432,
user = 'earthling',
password = 'extraterrestrial')
sql = conn.cursor()
def CREATE_TABLE(table, text):
sql.execute("CREATE TABLE " + table + " (" + text + ");")
def INSERT(table, url, text):
#date = datetime.date.today()
date = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
print date
query = "INSERT INTO " + table + " (url, text, date) VALUES (%s, %s, %s);"
params = (url, text, date,)
sql.execute(query, params)
def SELECT(table, url):
query = "SELECT * FROM " + table + " WHERE url = %s;"
sql.execute(query, (url,))
def QUERY(text):
sql.execute(text)
INSERT("main", "www.whoi.edu", "test")
print SELECT("main", "www.whoi.edu")
感谢您的帮助!
问题:这应该相当简单并且不需要 psycopg2?
能否分享一下您在尝试连接时遇到的问题?
就使用 Python 而言,我们必须使用 cx_oracle 连接到我们的 oracle 表,所以我希望您必须使用 psycopg2 连接 PostGresQL因为没有库可能就没有本机功能。
不过我刚刚读到你在 OS X 上,所以它可能完全不同。用 OS X 标记您的问题,看看这是否有助于更好地获取答案。
除了客户端库问题之外,您需要使用端口转发将 OpenShift 内部的 PostgreSQL 数据库公开到您的本地计算机。 OpenShift 内部的 PostgreSQL 服务的 IP 地址不会对外可见。请参阅有关使用 OpenShift 进行端口转发的教程,网址为:
我想我将使用本地 table(迷你哈希table),这比连接到远程数据库更快。
但是,另一个 SOLUTION 是(我相信使用 OpenShift 可能可行)从 OpenShift 创建 ROUTE 外部路径。如果 OpenShift 将来支持它,它可能会是这样的。安全性可能类似于 Dropbox 样式连接到 PostgreSQL 服务器。希望这些设置对某人有所帮助?但是,除非进行其他一些管理设置,否则它可能无法工作??!但是,但是,将来可能会有什么用? #local-made-up-mini-table-sql