diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-09-17 17:54:58 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-09-17 17:54:58 -0400 |
commit | 94d22e8b687d1f3896ee93d003331993a116db1b (patch) | |
tree | 89f17eea456dee9ae94179a39975b629626226b9 /termcast.py | |
parent | ab3b176bb73779b78a3a1e4ccd2b68f6abf3d543 (diff) | |
download | python-termcast-server-94d22e8b687d1f3896ee93d003331993a116db1b.tar.gz python-termcast-server-94d22e8b687d1f3896ee93d003331993a116db1b.zip |
handle utf8 decoding errors properly
Diffstat (limited to 'termcast.py')
-rw-r--r-- | termcast.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/termcast.py b/termcast.py index 25963ef..e94da82 100644 --- a/termcast.py +++ b/termcast.py @@ -29,8 +29,12 @@ class Handler(object): m = extra_data_re.search(self.buf) if m is None: break - extra_data_json = m.group(1) - extra_data = json.loads(extra_data_json.decode('utf-8')) + try: + extra_data_json = m.group(1).decode('utf-8') + extra_data = json.loads(extra_data_json) + except Exception as e: + print("failed to parse metadata: %s" % e, file=sys.stderr) + pass self.buf = self.buf[:m.start(0)] + self.buf[m.end(0):] if "geometry" in extra_data: self.rows = extra_data["geometry"][1] @@ -124,8 +128,12 @@ class Connection(object): extra_data = {} m = extra_data_re.match(buf) if m is not None: - extra_data_json = m.group(1) - extra_data = json.loads(extra_data_json.decode('utf-8')) + try: + extra_data_json = m.group(1).decode('utf-8') + extra_data = json.loads(extra_data_json) + except Exception as e: + print("failed to parse metadata: %s" % e, file=sys.stderr) + pass buf = buf[len(m.group(0)):] if "geometry" in extra_data: |