Post request and encoding

Karsten Hilbert Karsten.Hilbert at gmx.net
Mon Nov 2 12:32:09 EST 2020


On Mon, Nov 02, 2020 at 06:21:15PM +0100, Hernán De Angelis wrote:

For the record:

> Just reply to myself and whoever might find this useful.
>
> encode() must be done within the request call:

Nope (but it can, as you showed).

> header = {'Content-type':'application/xml', 'charset':'UTF-8'}
> response = requests.post(server, data=request.encode('utf-8'),
> headers=header)
>
> not in a previous separate line as I did.

Your separate line was wrong as much as ayone can guess:

> > I have tried of course adding
> >
> > request.encode('utf-8')
> >
> > before sending the request but it has not lead to a different result.

You would have needed to do:

request = request.encode('utf-8')

because .encode() does not operate in-place.

Karsten
--
GPG  40BE 5B0E C98E 1713 AFA6  5BC0 3BEA AC80 7D4F C89B


More information about the Python-list mailing list