Skip to content

Instantly share code, notes, and snippets.

@pebreo
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pebreo/17357df618808b9d6d4a to your computer and use it in GitHub Desktop.
Save pebreo/17357df618808b9d6d4a to your computer and use it in GitHub Desktop.
# 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:password@192.168.27.183: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