ValueError: invalid \x escape

Viewed 31241
python -c 'print "\x90" * 348 + "\x31\xc0\x83\xec\x01\x88\x04\x24\x68\x62\x61\x73\x68\x68\x62\x69\x6e\x2f\x8\xec\x01\xc6\x04\x24\x2f\x89\xe6\x50\x56\xb0\x0b\x89\xf3\x89\xe1\x31\xd2\xcd\x80\xb0\x01\x31\xdb\xcd\x80" + "\x30\xd1\xff\xff" * 35'
ValueError: invalid \x escape

Any idea what's causing this error ?

4 Answers

Also note that this error can occur if you do not escape a \ before an x in a multiline comment.

e.g. in Python 2.7:

def fn():
    """ Describing a file in the comments:
        C:\aaa\bbb\xxx\abc.txt
    """
    return None
fn()

raises the exception:

ValueError: invalid \x escape

Can be fixed by changing C:\aaa\bbb\xxx\abc.txt to C:\aaa\bbb\\xxx\abc.txt

Related