我试图从OS X Python脚本连接到OpenShift。 OpenShift肯定有用。但是,我正在寻找一个轻松的"使用python的方式,无需将其他PGSQL库下载到OS X.谢谢!
问题:用于此目的的正确域名是什么?如果不对python进行导入,我们可以保持简单吗?
我不想使用任何其他库。
我遇到的主要问题是pgsql.connect(dbname =' orion',host =' 127.7.74.2:5432',#' localhost& #39;,port = 5432,user =' earthling',password =' 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吗?
答案 0 :(得分:1)
除了客户端库的问题之外,您还需要使用端口转发将OpenShift内的PostgreSQL数据库暴露给本地计算机。 OpenShift中的PostgreSQL服务的IP地址不会在外部可见。请参阅以下有关使用OpenShift进行端口转发的教程:
答案 1 :(得分:0)
您可以分享尝试连接时遇到的问题吗?
就使用Python而言,我们必须使用cx_oracle连接到我们的oracle表,所以我希望你必须使用psycopg2连接PostGresQL,因为没有库可能没有本机功能。
但是我刚刚读到你的OS X,所以它可能完全不同。使用OS X标记您的问题,看看是否有助于更好地获取答案。
答案 2 :(得分:0)