Python 3: encode string queries to bytes