0

I need to use python to query a data repository to later export the result to php in order to make it available on the web. To do it I use:

print json.dumps(res)

where res is the output array. Unfortunately when I execute it I receive error:

python palina.py 70032
Traceback (most recent call last):
File "palina.py", line 17, in <module>
print json.dumps(res)
File "/usr/lib/python2.7/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python2.7/json/encoder.py", line 200, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python2.7/json/encoder.py", line 263, in iterencode
return _iterencode(o, 0)
File "/usr/lib/python2.7/json/encoder.py", line 177, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <DateTime '20140128T10:00:00' at 7f82ee9a5f80> is not JSON serializable

What other way of exporting the array exists without the need to serialize it? Or else, does exist some better serialization tool not producing this error?

Thanks,

Fabrizio Bartolomucci
  • 4,948
  • 8
  • 43
  • 75
  • This question shows how to get a Python datetime into JSON: [JSON datetime between Python and JavaScript](http://stackoverflow.com/q/455580/222914) – Janne Karila Jan 28 '14 at 09:33
  • Yes, thanks. Perhaps I am bit tired, but I did not get how it could solve my issue. I would have liked to pass everything as is to php to cope with it there, given I am not familiar with python. If I need to program in python, serialization is actually no longer an issue. – Fabrizio Bartolomucci Jan 28 '14 at 20:25
  • Actually I was said that I can connect to an XML-RPC server even by php, and that would solve a lot of problems. Still I did no find anything as clean as python from xmlrpclib import Server Have you got some suggestion on the easiest supporting library or some example about how to use it to replicate: s1 = Server('http://muovi.roma.it/ws/xml/autenticazione/1') s2 = Server('http://muovi.roma.it/ws/xml/paline/7') token = s1.autenticazione.Accedi(DEV_KEY, '') res = s2.paline.Previsioni(token, palina, 'it') Thanks. – Fabrizio Bartolomucci Jan 29 '14 at 10:54

0 Answers0