BUG: don't rely on sys.getdefaultencoding if we don't need to GH3360
ENH: save initial sys.getdefaultencoding() value aside for debugging
Merge pull request #3409 from y-p/GH3360c

BUG: don't rely on sys.getdefaultencoding if we don't need to