You cannot export binary data (from blob) in xml. The problem is that
GAE ignores your list of fields. Instead you can do

#xml tags
def export_xml(rows,fields):
    users=[]
    for row in rows: users.append(TAG.user(*[TAG[f](row[f]) for f in
fields]))
    return TAG.users(*users).xml()

#xml view
def lista():
    response.headers['Content-Type']='application/xml'
    return export_xml(db(db.auth_user.id>0).select(),
        ['bio','lat','lgt','first_name','country'])

On Oct 6, 11:59 am, Relsi Hur <[email protected]> wrote:
> well, in this way:
>
> db(db.auth_user.id>0).select(db.auth_user.bio, db.auth_user.lat,
> db.auth_user.lgt, db.auth_user.first_name, db.auth_user.country)
>
> Returns all fields of database, and not my selected, look:
> <users>
>     <user>
>         <auth_user.id>46005</auth_user.id>
>         <auth_user.first_name>Relsi</auth_user.first_name>
>         <auth_user.last_name>Hur Maron</auth_user.last_name>
>         <auth_user.email>[email protected]</auth_user.email>
>         <auth_user.password>87c709cdd4fe74117b8a9baf74f1ebc7</
> auth_user.password>
>         <auth_user.registration_key/>
>         <auth_user.reset_password_key/>
>         <auth_user.registration_id/>
>         <auth_user.avatar/>
>         <auth_user.bio>blablabla</auth_user.bio>
>         <auth_user.country>Brazil</auth_user.country>
>         <auth_user.site/>
>         <auth_user.lat>-32.7687993988</auth_user.lat>
>         <auth_user.lgt>-51.0204953125</auth_user.lgt>
>         <auth_user.avatar_blob>None</auth_user.avatar_blob>
>     </user>
> </users>
>
> but if I have a image in any record, the XML is not generated, the
> structure is broken in the element <auth_user.avatar_blob>, here no
> close the tag, just input this: \uffff\ufffd\ufffd\ufffd, and GAE
> returns a XML structure error.
>
> I not need all fields in XML, only those of my select, then I think
> that if he can return only the fields that I need the problem is
> solved, but the GAE execut my action in this way
> db(db.auth_user.id>0).select(db.auth_user.ALL), and not in this way
> db(db.auth_user.id>0).select(db.auth_user.bio, db.auth_user.lat,
> db.auth_user.lgt, db.auth_user.first_name, db.auth_user.country).
>
> On 6 out, 13:19, mdipierro <[email protected]> wrote:
>
> > I do not understand.
>
> > On Oct 6, 9:37 am, Relsi Hur <[email protected]> wrote:
>
> > > Thank you very much Massimo,
>
> > > Now returns alls fiels of model, but not complete structure, have
> > > error in image element:
>
> > > here: <auth_user.avatar_blob>\uffff\ufffd\ufffd\ufffd
>
> > > is not closing the tag, if have a image in db.
>
> > > On 6 out, 10:42, mdipierro <[email protected]> wrote:
>
> > > > Try replace
>
> > > > db().select(db.auth_user.bio, db.auth_user.lat,
> > > > db.auth_user.lgt, db.auth_user.first_name, db.auth_user.country)
>
> > > > with
>
> > > > db(db.auth_user.id>0).select(db.auth_user.bio, db.auth_user.lat,
> > > > db.auth_user.lgt, db.auth_user.first_name, db.auth_user.country)
>
> > > > On Oct 6, 2:23 am, Relsi Hur <[email protected]> wrote:
>
> > > > > Hello, I'm learning to use web2py and created a small application and
> > > > > deploy on GAE, in this app I have a action that return a xml:
>
> > > > > #xml tags
> > > > > def export_xml(rows):
> > > > >     idx=range(len(rows.colnames))
> > > > >     colnames=[item.replace('users.','') for item in rows.colnames]
> > > > >     users=[]
> > > > >     for row in rows.response: users.append(TAG['user']
> > > > > (*[TAG[colnames[i]](row[i]) for i in idx]))
> > > > >     return str(TAG['users'](*users))
>
> > > > > #xml view
> > > > > def lista():
> > > > >     response.headers['Content-Type']='application/xml'
> > > > >     return export_xml(db().select(db.auth_user.bio, db.auth_user.lat,
> > > > > db.auth_user.lgt, db.auth_user.first_name, db.auth_user.country))
>
> > > > > in localhost, this returns:
>
> > > > > <users>
> > > > >     <user>
> > > > >         <auth_user.bio>User bio</auth_user.bio>
> > > > >         <auth_user.lat>-31.0717547966</auth_user.lat>
> > > > >         <auth_user.lgt>-51.3720578125</auth_user.lgt>
> > > > >         <auth_user.first_name>Relsi</auth_user.first_name>
> > > > >         <auth_user.country>Brazil</auth_user.country>
> > > > >     </user>
> > > > > </users>
>
> > > > > but In GAE returns error:
>
> > > > > In FILE: /base/data/home/apps/web2pyople/1.345301654218685961/
> > > > > applications/init/controllers/default.py
>
> > > > > Traceback (most recent call last):
> > > > >   File "/base/data/home/apps/web2pyople/1.345301654218685961/gluon/
> > > > > restricted.py", line 178, in restricted
> > > > >     exec ccode in environment
> > > > >   File "/base/data/home/apps/web2pyople/1.345301654218685961/
> > > > > applications/init/controllers/default.py:lista", line 45, in <module>
> > > > >   File "/base/data/home/apps/web2pyople/1.345301654218685961/gluon/
> > > > > globals.py", line 96, in <lambda>
> > > > >     self._caller = lambda f: f()
> > > > >   File "/base/data/home/apps/web2pyople/1.345301654218685961/
> > > > > applications/init/controllers/default.py:lista", line 43, in lista
> > > > >   File "/base/data/home/apps/web2pyople/1.345301654218685961/gluon/
> > > > > contrib/gql.py", line 678, in select
> > > > >     (items, tablename, fields) = self._select(*fields, **attributes)
> > > > >   File "/base/data/home/apps/web2pyople/1.345301654218685961/gluon/
> > > > > contrib/gql.py", line 630, in _select
> > > > >     table = self._get_table_or_raise()
> > > > >   File "/base/data/home/apps/web2pyople/1.345301654218685961/gluon/
> > > > > contrib/gql.py", line 609, in _get_table_or_raise
> > > > >     raise SyntaxError, 'Set: no tables selected'
> > > > > SyntaxError: Set: no tables selected
>
> > > > > what am I doing wrong?
>
>

Reply via email to