0
votes

I'm trying to connect to OpenShift from a OS X Python Script. OpenShift for sure works. However, I'm looking for an "easy" way with python without downloading additional PGSQL libs to OS X. Thanks!

Question: What is the correct domain name to use for this?? And can we keep it simple without doing an import to python?

I don't want to use any additional libraries.

the main problem I'm having is with pgsql.connect(dbname = 'orion', host = '127.7.74.2:5432', #'localhost', port = 5432, user = 'earthling', password = 'extraterrestrial')

Here is what the code file looks like "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")

OpenShift User Menu

Thanks for your help!

Question: This should fairly simple and shouldn't require psycopg2?

3
I talked with a friend and they basically said I have to use BREW or PIP to install a custom SQL access library. When is python going to get a pgsql or mysql direct access???!!! - Asher

3 Answers

1
votes

Separate to the issue of client side libraries you need use port forwarding to expose the PostgreSQL database inside of OpenShift to your local computer. The IP address of the PostgreSQL service inside of OpenShift is not going to be externally visible. See the tutorial about port forwarding with OpenShift at:

0
votes

Can you share what problem you're having when you attempt to connect?

As far as working with Python, we've had to use cx_oracle to connect to our oracle tables, so I'd expect you'd have to use psycopg2 to connect with PostGresQL as there's probably not a native functionality without a library.

However I just read you're on OS X, so it may be entirely different. Tag your question with OS X, see if that helps fetch an answer better.

0
votes

I think I'm going to use a local table (mini-hashtable) and this will be faster then connecting to a remote database.

However, the other SOLUTION is (i believe maybe possible with OpenShift) to create ROUTE an External path from OpenShift. Here is what it MAYBE looks like if OpenShift supports this in the future. Security can maybe work similar to dropbox style connections to a PostgreSQL server. Hopefully these settings will help someone? However, it maybe will not work unless some other admin settings are made??! However, However, something maybe could work in the future? #local-made-up-mini-table-sql

ROUTES External Traffic

CREATE ROUTE