This is also how other languages http libraries seem to deal with this, sending in unicode just works:
In cURL (works fine):
curl http://example.com -d "Celebrate 🎉"
In Ruby with http.rb (works fine):
require 'http'
r = HTTP.post("http://example.com", :body => "Celebrate 🎉)
In Node with request (works fine):
var request = require('request');
request.post({url: 'http://example.com', body: "Celebrate 🎉"}, function (error, response, body) {
console.log(body)
})
But Python 3 with requests crashes instead:...with the following stacktrace:
import requests
r = requests.post("http://localhost:8000/tag", data="Celebrate 🎉")
...
File "../lib/python3.4/http/client.py", line 1127, in _send_request
body = body.encode('iso-8859-1')
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 14-15: ordinal not in range(256)