On Saturday, 1 October 2011 09:40:26 UTC+2, seongjoo wrote:
>
> I figured out what the problem was but forgot to come back to the
> forum.
>
> The problem was that the keys of the dictionary was encoded as
> unicode, for example u'keyname'. It was in unicode because the dict is
> loaded from json. Specify their encoding as UTF-8 with following
> routine, solved the problem.
>
> def loadFromJson(jsonData):
> data=json.loads(jsonData, encoding='utf-8')
>
> #encode the keys as UTF-8
> return dict((k.encode('utf-8'),v) for (k,v) in data.items())
>
I have a related problem but this solution does not help me.
The model:
db.define_table('rjoern_uitgawe',
Field('ui', 'string', length=10), #unieke id
Field('rj_id',
requires = IS_IN_DB(db, db.rjoernaal.sn, '%(so)s')),
#joernaal
Field('vl', length=10), # volume
Field('ris', length=10), # issue
Field('py', length=4), #publication year
Field('pd', length=20), #publication date
Field('su', length=10), #supplement
Field('si', length=10) #special issue
)
The code:
321 print uitg
322 rpub_id = db.rjoern_uitgawe.insert(**uitg)
The result:
{'ui': '0002851186', 'py': '2010', 'vl': '24', 'ris': '4', 'pd': 'NOV'}
Traceback (most recent call last):
File "/home/js/web2py/gluon/shell.py", line 223, in run
execfile(startfile, _env)
File "/home/js/dokumente/werk/senwet/isi-data/data/lees_isi.py", line 412,
in <module>
hanteer_data(data)
File "/home/js/dokumente/werk/senwet/isi-data/data/lees_isi.py", line 368,
in hanteer_data
hanteer_joernaal(data)
File "/home/js/dokumente/werk/senwet/isi-data/data/lees_isi.py", line 361,
in hanteer_joernaal
skryf_joernaaldata(joernaal, publisher, uitgawe)
File "/home/js/dokumente/werk/senwet/isi-data/data/lees_isi.py", line 322,
in skryf_joernaaldata
rpub_id = db.rjoern_uitgawe.insert(**uitg)
File "/home/js/web2py/gluon/dal.py", line 7867, in insert
self._attempt_upload(fields)
File "/home/js/web2py/gluon/dal.py", line 7852, in _attempt_upload
if field.type=='upload' and field.name in fields:
AttributeError: 'str' object has no attribute 'type'
What is going on here?
Regards
Johann
--