nicolargo / glances

Glances an Eye on your system. A top/htop alternative for GNU/Linux, BSD, Mac OS and Windows operating systems.
http://nicolargo.github.io/glances/
Other
26.83k stars 1.53k forks source link

500 Internal Server Error /api/3/network/interface_name #1401

Closed VinhLoiIT closed 5 years ago

VinhLoiIT commented 5 years ago

Description

Hi there, I recently found the bug in RESTful-API I have got the latest version of glances from python3-pip installer When I start the webserver via: glances -w -p 8282 And access the RESTful-API: localhost:8282/api/3/network/interface_name (the one I just copied from https://github.com/nicolargo/glances/wiki/The-Glances-RESTFULL-JSON-API), I got the 500 Internal Server Error Read the Trace back log: Traceback (most recent call last): File "/home/vinhloiit/glances/env/bin/bottle.py", line 862, in _handle return route.call(**args) File "/home/vinhloiit/glances/env/bin/bottle.py", line 1740, in wrapper rv = callback(*a, **ka) File "/home/vinhloiit/glances/env/lib/python3.6/site-packages/glances/outputs/glances_bottle.py", line 619, in _enable_cors return fn(*args, **kwargs) File "/home/vinhloiit/glances/env/lib/python3.6/site-packages/glances/outputs/glances_bottle.py", line 45, in wrapper ret = func(*args, **kwargs) File "/home/vinhloiit/glances/env/lib/python3.6/site-packages/glances/outputs/glances_bottle.py", line 499, in _api_item return self._api_itemvalue(plugin, item) File "/home/vinhloiit/glances/env/lib/python3.6/site-packages/glances/outputs/glances_bottle.py", line 45, in wrapper ret = func(*args, **kwargs) File "/home/vinhloiit/glances/env/lib/python3.6/site-packages/glances/outputs/glances_bottle.py", line 473, in _api_itemvalue ret = self.stats.get_plugin(plugin).get_stats_item(item) File "/home/vinhloiit/glances/env/lib/python3.6/site-packages/glances/plugins/glances_plugin.py", line 393, in get_stats_item return self._json_dumps({item: map(itemgetter(item), self.stats)}) File "/home/vinhloiit/glances/env/lib/python3.6/site-packages/glances/plugins/glances_plugin.py", line 148, in _json_dumps return json.dumps(d) File "/usr/lib/python3.6/json/__init__.py", line 231, in dumps return _default_encoder.encode(obj) File "/usr/lib/python3.6/json/encoder.py", line 199, in encode chunks = self.iterencode(o, _one_shot=True) File "/usr/lib/python3.6/json/encoder.py", line 257, in iterencode return _iterencode(o, 0) File "/usr/lib/python3.6/json/encoder.py", line 180, in default o.__class__.__name__) TypeError: Object of type 'map' is not JSON serializable

Well, the error from map in _json_dumps in glances_plugin.py, I found on https://stackoverflow.com/questions/33989430/map-object-is-not-json-serializable and see that this map is not the same as python 2

Versions

Logs

https://pastebin.com/1hF1fSNy

nicolargo commented 5 years ago

Hi @VinhLoiIT Many thanks for the issue report.

I just publish a patch on the DEVELOP branch. Can you test it ?

VinhLoiIT commented 5 years ago

Hi @VinhLoiIT Many thanks for the issue report.

I just publish a patch on the DEVELOP branch. Can you test it ?

Yeah this issues is solved. Should I append a short code in unittest-restful.py?

nicolargo commented 5 years ago

I will...

Thanks !

nicolargo commented 5 years ago

Done in latest commit.