Hi,
The api output comes up with the special charaters such as newline and \.
The output looks good when i'm executing from the IDE. but while looking
towards the url, it shows up like below and not in good format. It
becomes trouble while on the retrival.
"[{\"INFO\": null, \"SEQ\": 1.0, \"TOPIC\": \"@\"}, {\"INFO\": \" @
(\\\"at\\\" sign)\", \"SEQ\": 2.0, \"TOPIC\": \"@\"}, {\"INFO\": \"
-------------\", \"SEQ\": 3.0, \"TOPIC\": \"@\"}, {\"INFO\": \" Runs the
SQL*Plus statements in the specified script. The script can be\", \"SEQ\":
4.0, \"TOPIC\": \"@\"}, {\"INFO\": \" called from the local file system or
a web server.\", \"SEQ\": 5.0, \"TOPIC\": \"@\"}, {\"INFO\": null, \"SEQ\":
6.0, \"TOPIC\": \"@\"}, {\"INFO\": \" @ {url|file_name[.ext]} [arg ...]\",
\"SEQ\": 7.0, \"TOPIC\": \"@\"}, {\"INFO\": null, \"SEQ\": 8.0, \"TOPIC\":
\"@\"}, {\"INFO\": \" where url supports HTTP and FTP protocols in the
form:\", \"SEQ\": 9.0, \"TOPIC\": \"@\"}, {\"INFO\": null, \"SEQ\": 10.0,
\"TOPIC\": \"@\"}, {\"INFO\": \" http://host.domain/script.sql\", \"SEQ\":
11.0, \"TOPIC\": \"@\"}, {\"INFO\": null, \"SEQ\": 12.0, \"TOPIC\": \"@\"},
{\"INFO\": null, \"SEQ\": 1.0, \"TOPIC\": \"@@\"}, {\"INFO\": \" @@ (double
\\\"at\\\" sign)\", \"SEQ\": 2.0, \"TOPIC\": \"@@\"}, {\"INFO\": \"
---------------------\", \"SEQ\": 3.0, \"TOPIC\": \"@@\"}, {\"INFO\": null,
\"SEQ\": 4.0, \"TOPIC\": \"@@\"}, {\"INFO\": \" Runs the specified script.
This command is almost identical to\", \"SEQ\": 5.0, \"TOPIC\": \"@@\"},
{\"INFO\": \" the @ command. It is useful for running nested scripts
because it\", \"SEQ\": 6.0, \"TOPIC\": \"@@\"}, {\"INFO\": \" has the
additional functionality of looking for the nested script\", \"SEQ\": 7.0,
\"TOPIC\": \"@@\"}, {\"INFO\": \" in the same url or path as the calling
script.\", \"SEQ\": 8.0, \"TOPIC\": \"@@\"}, {\"INFO\": null, \"SEQ\": 9.0,
\"TOPIC\": \"@@\"}, {\"INFO\": \" @@ {url|file_name[.ext]} [arg ...]\",
\"SEQ\": 10.0, \"TOPIC\": \"@@\"}, {\"INFO\": null, \"SEQ\": 11.0,
\"TOPIC\": \"@@\"}, {\"INFO\": null, \"SEQ\": 1.0, \"TOPIC\": \"/\"},
{\"INFO\": \" / (slash)\", \"SEQ\": 2.0, \"TOPIC\": \"/\"}, {\"INFO\": \"
---------\", \"SEQ\": 3.0, \"TOPIC\": \"/\"}, {\"INFO\": null, \"SEQ\":
4.0, \"TOPIC\": \"/\"}, {\"INFO\": \" Executes the most recently executed
SQL command or PL/SQL block\", \"SEQ\": 5.0, \"TOPIC\": \"/\"}, {\"INFO\":
\" which is stored in the SQL buffer. Use slash (/) at the command\",
\"SEQ\": 6.0, \"TOPIC\": \"/\"}, {\"INFO\": \" prompt or line number prompt
in SQL*Plus command line. The buffer\", \"SEQ\": 7.0, \"TOPIC\": \"/\"},
{\"INFO\": \" has no command history and does not record SQL*Plus
commands.\", \"SEQ\": 8.0, \"TOPIC\": \"/\"}
Program Code...
import flask_restful_extend
import collections
from flask import Flask, jsonify, json
from flask_restful import reqparse, abort, Api, Resource
from sqlalchemy.ext.declarative import DeclarativeMeta
from sqlalchemy import create_engine
from sqlalchemy import MetaData, Column, Table, ForeignKey
from sqlalchemy import Integer, String
from sqlalchemy import select
from IPython.utils.tests.test_capture import hello_stderr
engine =
create_engine('oracle://system:[email protected]:1521/dsv01p01',echo=True)
metadata = MetaData(bind=engine)
conn = engine.connect()
users_table = Table('HELP', metadata,autoload=True)
s = select([users_table])
res = conn.execute(s)
rows = res.fetchall()
print rows
#print rows.JSONEncoder
print "hello"
objects_list = []
for row in rows:
d = collections.OrderedDict()
d['TOPIC'] = row.topic
d['SEQ'] = row.seq
d['INFO'] = row.info
objects_list.append(d)
j = json.dumps(objects_list)
print j
app = Flask(__name__)
api = Api(app)
def abort_if_row_doesnt_exist(row_id):
if row_id not in rows:
abort(404, message="row {} doesn't exist".format(row_id))
parser = reqparse.RequestParser()
class help_rows(Resource):
def get(self, row_id):
abort_if_row_doesnt_exist(row_id)
return rows[row_id]
class helplist(Resource):
def get(self):
return j
api.add_resource(helplist, '/help_rows')
api.add_resource(help_rows, '/help_rows/<row_id>')
if __name__ == '__main__':
app.run(host='localhost',port=8090,debug=True)
Thanks,
Ramesh G
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.