Issue #635 duplicate

Pygmentize throws TypeError on Python 3.2

David Baumgold
created an issue

I have installed Pygments 1.4 on both Python 2.7.1 and for Python 3.2rc2. I have an XML file that I want to highlight in my terminal. When I use pygmentize-2.7, the file highlights properly. When I use pygmentize-3.2, I get the following error:

{{{ *** Error while highlighting: TypeError: must be str, not bytes (file "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/codecs.py", line 356, in write) }}}

I'm running OS X 10.6.6, and I've installed Python and Pygmentize via Macports 1.9.2, if it makes any difference. (I'm writing a Portfile for Pygments on Python 3.2, and will publish it when it works.)

Comments (3)

  1. Anonymous

    I created an adhoc fix for this: <pre> 345c345 < outfile = sys.stdout.buffer ---

    outfile = codecs.getwriter('utf-8')(sys.stdout.buffer)

    406c406 < #if sys.version_info < (3,): ---

    if sys.version_info < (3,):

    </pre> I haven't tested it extensively, but it works with: a) pygmentize stdout no encoding b) pygmentize stdout with encoding c) pygmentize fileout no encoding d) pygmentize fileout with encoding

  2. Anonymous
    Sorry about the ugly post earlier
    #!diff
    345c345
    <         outfile = sys.stdout.buffer
    ---
    >         outfile = codecs.getwriter('utf-8')(sys.stdout.buffer)
    406c406
    <             #if sys.version_info < (3,):
    ---
    >             if sys.version_info < (3,):
    
  3. Log in to comment