On Thu, Jul 3, 2014 at 8:48 AM, 'Frank Liou' via sqlalchemy
<sqlalchemy@googlegroups.com> wrote:
> def get_query():
>     conn = engine.connect()
>     check = 'SELECT * FROM friends'
>     obj = [conn.execute(check)]
>     jqs = json.dumps(obj)
>     return jqs
>
>
>
> result is
>
> Internal Server Error
>
> The server encountered an internal error and was unable to complete your
> request. Either the server is overloaded or there is an error in the
> application.
>
>
> if i change obj = '123'
>
> it will show 123
>
>
> but when i use execute to query
>
> it will no request
>
> how can that be?
>
> is it wrong type to catch?
>
>
> pleaese help me .thanks
>

Firstly, when you get a message like that from your web server, you
can normally find the full error message in the web server logs. The
location of those depends on how the server has been set up, but they
are usually somewhere like /var/log/httpd/error_log or
/var/log/apache2/error_log on Linux.

If you looked in there, I think you would probably see a stack trace
ending with a message about being unable to convert a ResultProxy to
json. After this:

    obj = [conn.execute(check)]

"obj" is now a list containing a single element, which is a
ResultProxy object. You probably wanted something like this instead:

    obj = conn.execute(check).fetchall()

After running that, obj will now be a list of rows from the database.
However, you still won't be able to convert it directly to json,
because each row is a RowProxy object, and the json library doesn't
know how to handle RowProxy objects.

The simplest thing would probably be to convert each row to a dictionary:

    rows = conn.execute(check).fetchall()
    obj = [dict(row.items()) for row in rows]

Hope that helps,

Simon

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to