Js2Py icon indicating copy to clipboard operation
Js2Py copied to clipboard

UnicodeDecodeError: 'ascii' codec can't decode byte

Open scratchmex opened this issue 5 years ago • 1 comments

I was trying the parser in http://piter.io/projects/js2py and I got this error. The input text to parse is included.

Input
var TralbumData = {
    current: {
        "upc": null,
        "mod_date": "11 Jan 2018 12:43:36 GMT",
        "publish_date": "23 Dec 2017 07:24:16 GMT",
        "title": "Ebony/Ivory (neji-190)",
        "audit": 0,
        "art_id": 2748926967,
        "set_price": 7.0,
        "download_pref": 2,
        "killed": null,
        "purchase_url": null,
        "download_desc_id": null,
        "band_id": 1283307892,
        "new_desc_format": 1,
        "minimum_price_nonzero": 8.0,
        "featured_track_id": 3634659335,
        "auto_repriced": null,
        "about": "ヘ(゚ω゚ヘ)彡\r\n\r\nX÷(Z/4)=Y=Ebony/Ivory\r\n\r\nproduced by Satanicpornocultshop\r\nphoto by vinylman\r\nart direction by ugh",
        "artist": null,
        "private": null,
        "purchase_title": null,
        "minimum_price": 8.0,
        "id": 4136800420,
        "selling_band_id": 1283307892,
        "credits": "サタポの Ebony/Ivory、ミニマルかつめちゃスタイリッシュな高級テクノ! お正月休みは短いけど、うまい冷酒と御節料理とこのアルバムがあればきっと大丈夫。(taiki50storm/ORRORINZ)\r\n\r\n無駄が一切ないサウンドはとても肉体的。純度が高く身体に吸収されていく。劇場、例えば世田谷パブリックシアターにおけるダンス・パフォーマンスとクラブの壁を取り払い鳴りつづける。(@cyclepistols)\r\n\r\nサタポさんのニューEP、深め音響にテッキーなトラックでめちゃかっくいい (vamulet(v.o.c))",
        "release_date": "23 Dec 2017 00:00:00 GMT",
        "require_email": null,
        "type": "album",
        "require_email_0": null,
        "is_set_price": null,
        "new_date": "21 Dec 2017 13:58:09 GMT"
    }
}
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 580: ordinal not in range(128)

-----------------------
FULL PYTHON TRACEBACK:
Traceback (most recent call last):
  File "/base/data/home/apps/s~piotr-dabkowski/1.405218710605697848/main.py", line 28, in post
    res = translate_js(self.request.body)
  File "/base/data/home/apps/s~piotr-dabkowski/1.405218710605697848/lib/js2py/translators/translator.py", line 62, in translate_js
    parsed = parser.parse(js) # js to esprima syntax tree
  File "/base/data/home/apps/s~piotr-dabkowski/1.405218710605697848/lib/js2py/translators/pyjsparser.py", line 2842, in parse
    self.source = unicode(code) + ' \n ; //END' # I have to add it in order not to check for EOF every time
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 580: ordinal not in range(128)

scratchmex avatar Feb 29 '20 23:02 scratchmex

I'm getting a similar error. I'm on Windows where I understand the default encoding is cp1252, NOT utf-8. Input is the standard ssf.js Excel formatter (https://raw.githubusercontent.com/SheetJS/ssf/master/ssf.js). Error:

>>> import js2py
>>> js2py.translate_file('ssf.js', 'ssf.py')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Joe Orost\AppData\Local\Programs\Python\Python37-32\lib\site-packages\js2
py\evaljs.py", line 81, in translate_file
    write_file_contents(output_path, out)
  File "C:\Users\Joe Orost\AppData\Local\Programs\Python\Python37-32\lib\site-packages\js2
py\evaljs.py", line 57, in write_file_contents
    f.write(contents)
  File "C:\Users\Joe Orost\AppData\Local\Programs\Python\Python37-32\lib\encodings\cp1252.
py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 7681-7682: charact
er maps to <undefined>

Avoidance:

>>> js = open('ssf.js', 'r', encoding="utf-8").read()
>>> py = js2py.translate_js(js)
>>> open('ssf.py', 'w', encoding="utf-8").write(py)

snoopyjc avatar Sep 13 '20 14:09 snoopyjc