Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

url preview fails with exceptions.TypeError: Data must not be unicode #2915

Closed
johnfoo opened this issue Feb 27, 2018 · 2 comments
Closed

url preview fails with exceptions.TypeError: Data must not be unicode #2915

johnfoo opened this issue Feb 27, 2018 · 2 comments
Labels
z-bug (Deprecated Label) z-p2 (Deprecated Label)

Comments

@johnfoo
Copy link

johnfoo commented Feb 27, 2018

when sending a message containing an URL to preview, the previewing process fails with the following stack trace

Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1532, in unwindGenerator
return _inlineCallbacks(None, gen, Deferred())
File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1386, in _inlineCallbacks
result = g.send(result)
File "/usr/local/lib/python2.7/dist-packages/synapse/http/server.py", line 119, in wrapped_request_handler
yield request_handler(self, request)
File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1532, in unwindGenerator
return _inlineCallbacks(None, gen, Deferred())
--- ---
File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1386, in _inlineCallbacks
result = g.send(result)
File "/usr/local/lib/python2.7/dist-packages/synapse/rest/media/v1/preview_url_resource.py", line 155, in _async_render_GET
respond_with_json_bytes(request, 200, og, send_cors=True)
File "/usr/local/lib/python2.7/dist-packages/synapse/http/server.py", line 405, in respond_with_json_bytes
request.write(json_bytes)
File "/usr/local/lib/python2.7/dist-packages/twisted/web/server.py", line 234, in write
http.Request.write(self, data)
File "/usr/local/lib/python2.7/dist-packages/twisted/web/http.py", line 1086, in write
self.channel.write(data)
File "/usr/local/lib/python2.7/dist-packages/twisted/web/http.py", line 2307, in write
self.transport.write(data)
File "/usr/local/lib/python2.7/dist-packages/twisted/internet/_newtls.py", line 191, in write
FileDescriptor.write(self, bytes)
File "/usr/local/lib/python2.7/dist-packages/twisted/internet/abstract.py", line 352, in write
raise TypeError("Data must not be unicode")
exceptions.TypeError: Data must not be unicode

the issue stems from http/server.py, twisted does not seem to appreciate to receive improperly encoded data. simply encoding in utf8 the json_bytes fixes the problem

--versions
environment: docker (from silvio/docker-matrix)
synapse: master (3d5a254)
python: 2.7.13
twisted: 17.9.0

created PR #2916 with the fix

@richvdh
Copy link
Member

richvdh commented Feb 28, 2018

suspect this is closely related to #2891.

@hawkowl
Copy link
Contributor

hawkowl commented Nov 7, 2018

This ought to be fixed by #4157 .

@hawkowl hawkowl closed this as completed Nov 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
z-bug (Deprecated Label) z-p2 (Deprecated Label)
Projects
None yet
Development

No branches or pull requests

4 participants