Python 3.9 is now generally available.

google.appengine.api.appinfo.EnsureAsciiString

Ensure s contains only ASCII-safe characters; return it as bytes-type.

s the string or bytes to check.
err the error to raise if not good.

err if it's not ASCII-safe.

s as a string. In python2, string as byte. In python3m string as unicode.