Using Pycurl:
POST /post HTTP/1.1
User-Agent: PycURL/7.32.0
Host: 127.0.0.1:4000
Accept: */*
Key:key
Sign:sign
Content-Length: 3
Content-Type: application/x-www-form-urlencoded
foo
With requests:
POST /post HTTP/1.1
Host: 127.0.0.1:4000
Accept-Encoding: identity
Content-Length: 3
Key: key
Sign: sign
foo
There are several differences which could lead to your error:
Missing
User-Agent
andAccept
headers. This is because you overwrite thesession.headers
attribute which contains those default headers. Try this instead:session.headers.update({'Key': key, 'Sign': sign})
Missing
Content-Type
header. I think you passed a string as themessage
parameter. Requests doesn't know that this isapplication/x-www-form-urlencoded
and therefore doesn't set the relevant header. Either:- Set the header yourself
- Better: pass requests a dictionary of your parameters. They will be encoded and declared correctly