Last active
August 29, 2015 14:02
-
-
Save pebreo/17357df618808b9d6d4a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://stackoverflow.com/questions/14249115/serializing-output-to-json-valueerror-circular-reference-detected | |
from sqlalchemy import * | |
from sqlalchemy.orm import sessionmaker, scoped_session | |
from sqlalchemy.sql import text | |
def f(): | |
print 'hello' | |
engine = create_engine('mysql://readonly:[email protected]:3306/efn') | |
Session = scoped_session(sessionmaker(bind=engine)) | |
s = Session() | |
result = s.execute('SELECT name FROM Answers WHERE answer_ID in (100,101,102) limit 5', {'val': 5}) | |
print result.fetchall() | |
products_json = [] | |
for code in best_matching_codes: | |
cur = db.cursor() | |
query = "SELECT * FROM %s WHERE code LIKE '%s'" % (PRODUCTS_TABLE_NAME, product_code) | |
cur.execute(query) | |
columns = [desc[0] for desc in cur.description] | |
rows = cur.fetchall() | |
for row in rows: | |
products_json.append(dict((k,v) for k,v in zip(columns,row))) | |
return json.dumps(products_json, default = date_handler) | |
def date_handler(obj): | |
if hasattr(obj, 'isoformat'): | |
return obj.isoformat() | |
else: | |
json.JSONEncoder.default(self,obj) | |
f() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment