I'm using python requests 2.2.1, and trying to post a request with a custom header.
I'm creating my own header, myheader
, like this:
myheader = {'name' : myvalue }
The thing is myvalue
is a unicode object. I'm not encoding it to a byte string, just directly putting it in the myheader
dictionary.
and when I do:
r = requests.post(myhost, headers=myheader)
I get an exception:
UnicodeEncodeError: 'ascii' codec can't encode characters in position 17-18: ordinal not in range(128)
And I guess I could get rid of it by doing myvalue.encode('utf8')
before putting it in the header
dictionary - but my question is, is it illegal then to put a unicode object in the header? I ask because the response can contain unicode objects with no problem, so why can I not put one in the header?