getgauge / gauge

Light weight cross-platform test automation
https://gauge.org
Apache License 2.0
2.99k stars 344 forks source link

UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 585: illegal multibyte sequence #1228

Closed 0xn0ne closed 6 years ago

0xn0ne commented 6 years ago

Expected behavior

System: windows 10 Build 17134 Local Python: Python 3.6.5 :: Anaconda, Inc.

When I finish the specification, I want the program to run. But this problem occurred.

Actual behavior

This problem occurred when I tried to start the program.

Traceback (most recent call last):
  File "start.py", line 67, in <module>
    main()
  File "start.py", line 26, in main
    load_implementations()
  File "start.py", line 33, in load_implementations
    load_files(d)
  File "C:\Users\Blueshark-JF\AppData\Roaming\Python\Python36\site-packages\getgauge\static_loader.py", line 24, in load_files
    pf = PythonFile.parse(file_path)
  File "C:\Users\Blueshark-JF\AppData\Roaming\Python\Python36\site-packages\getgauge\parser.py", line 18, in parse
    return PythonFile.Class.parse(file_path, content)
  File "C:\Users\Blueshark-JF\AppData\Roaming\Python\Python36\site-packages\getgauge\parser_parso.py", line 30, in parse
    content = f.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 585: illegal multibyte sequence

I went to check my script and found that I wrote Chinese notes in the script, such as this:

def do_requests(method, url, retry_time=3, **kwargs):
    while retry_time:
        try:
            return session.request(method, url, **kwargs)
        except requests.exceptions.ConnectionError:
            # Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。
            pass
        retry_time -= 1

Steps to reproduce

  1. Initialize an project using the gauge init python command
  2. Write any Chinese character in the .py script, Such as the following image
  3. This problem can occur using the gauge run command or the gauge run specs /

Gauge version

# gauge -v
Gauge version: 1.0.3
Commit Hash: ff6c0c3

Plugins
-------
html-report (4.0.5)
python (0.3.4)
screenshot (0.0.1)
sswaroopgupta commented 6 years ago

@0xNone

As mentioned in https://github.com/getgauge/gauge-python/issues/86#issuecomment-396228074 please use # -*- coding: utf-8 -*- to tell explicitly that utf-8 encoding is used.

screen shot 2018-10-24 at 11 23 32 am
0xn0ne commented 6 years ago

Thanks your reply. I know this way, but it doesn't work in Windows system. This solution seems to work in Python 2.x.

sswaroopgupta commented 6 years ago

@0xNone I ran this on Windows 10 Pro with Python 3.7 and this works as expected. Which version of Windows are you on?

working_on_windows

0xn0ne commented 6 years ago

em...

I think this should be the reason why the system default language, because in Windows, when the regional language is selected as Chinese, the system code will change to GBK

image

And when I changed the area to English, it works fine now. Thank you again for your answer.

image