welovewordpress / SublimePhpTidy

Plugin for Sublime Text 2 to format PHP code to meet the WordPress Coding Standards using a modified version of phptidy
GNU General Public License v2.0
109 stars 30 forks source link

UnicodeDecodeError #23

Open edpittol opened 11 years ago

edpittol commented 11 years ago

When I applied the Tidy PHP command in the console appear it:

Traceback (most recent call last):
  File "./sublime_plugin.py", line 362, in run_
  File "./php_tidy.py", line 83, in run
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 420: ordinal not in range(128)

It's because my code has a 'ã' char.

admtech commented 11 years ago

My easy solution (Mac OS X 10.9, Sublime 2):

In file: .../Sublime Text 2/Packages/PhpTidy/php_tidy.py

Change Row 73 from: newContent = fileHandle.read() in in newContent = fileHandle.read().decode('utf-8')

Now, PhpTidy works fine (for me). Check the Sublime Console Output for details or errors. Here the solution in german language: http://www.administrator.de/contentid/221695

best regards Admtech

raamdev commented 10 years ago

Yup, I just experienced this same error. I'm on Mac OS X 10.9 running Sublime 2.

@admtech Your solution fixed it for me. Thanks!

lumberman commented 10 years ago

For those who struggle to find what character cause problem: this quickly created plugin ( http://stackoverflow.com/a/13002055 ) helped me to find position of a problematic character in my code.

arnalyse commented 10 years ago

thanks @admtech, your solution worked perfectly for me :)

oxk4r01 commented 8 years ago

When I run PhpTidy, nothing happens, and I get this error in the console: Traceback (most recent call last): File ".\sublimeplugin.py", line 362, in run File ".\php_tidy.py", line 61, in run UnicodeEncodeError: 'ascii' codec can't encode character u'\xd3' in position 18: ordinal not in range(128) Writing file /C/xampp/htdocs/Oscar/asdfasdf.php with encoding UTF-8

I tried the solution proposed her, but it didn't work. My error is sligthly different from the one posted in here. Could somebody help me with this, please?

zedejose commented 8 years ago

I've tried @admtech's solution which didn't work for me (Sublime 3, OSX).

What did work, was changing line 72 (not 73) in .../Sublime Text 3/Packages/PhpTidy/php_tidy.py

from:

fileHandle = open ( tmpfile, 'r' )

to

fileHandle = open ( tmpfile, 'r', encoding='utf-8' )