0

I installed 3.5.1 Python several months ago on Windows 7. I have a python program which is in .py file. It runs fine from IDLE Python.

However, when I run it from command prompt, it says:

C:\_1\Python>info_.py
START -------------------------
Traceback (most recent call last):
  File "C:\_1\Python\info_.py", line 33, in <module>
    print (data)
  File "C:\Program Files\Python35\lib\encodings\cp866.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\xab' in position 18
4: character maps to <undefined>

data is:

u = urllib.request.urlopen('http://www.****')
data = u.read()

I want to run programs from prompt too. What could I do to be sure my code works same in IDLE and via command prompt on Windows?

1

1 Answer 1

1

Try using encode

print(data.encode('utf-8'))
Sign up to request clarification or add additional context in comments.

1 Comment

This is just printing the repr of a bytes object, so "«" will print as b'\xc2\xab'. Printing Unicode in the Windows console requires a separate wide-character API that Python doesn't use by default. Install win_unicode_console to enable this API.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.