[Twisted-Python] treq POST abborting with: err: ('Could not adapt', '{"....", "..."} <InterfaceClass twisted.web.iweb.IBodyProducer>)

Glyph Lefkowitz glyph at twistedmatrix.com
Fri Jan 6 18:22:37 MST 2017


1
> On Jan 6, 2017, at 3:36 PM, Tristan Seligmann <mithrandi at mithrandi.net> wrote:
> 
> On Fri, 6 Jan 2017 at 21:21 steven meiers <commercials24 at yahoo.de <mailto:commercials24 at yahoo.de>> wrote:
> glyph (without seeing the the code or backtrace) suggested that:
> "I think the issue might be that it doesn't support bytes() on py3,
> it's registered against str() or something"
> 
> Actually, the problem is the reverse of this; only bytes is supported, but you're passing str (unicode) in. 

Aah, thanks for pointing this out.

>         somepage = yield treq.post(target_url, json.dumps({hmac: key,
> "username": username, 'pw':'', 'gender':'m', 'aaaa':''}),
> 
> json.dumps returns str (ie. unicode) on py3; throwing in a .encode('utf-8') here is probably what you want.


Maybe we should support unicode for the body as well.  We can set the charset in the mime-type and everything so that it will be properly intelligible by the server, which doesn't happen if the user manually encodes like this.

Even if we do this though - is there any way to convince json.dumps to behave consistently between 2/3 for the purposes of examples?

-glyph

-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20170106/5cc700ab/attachment-0002.html>


More information about the Twisted-Python mailing list