OmniMarkupPreviewer icon indicating copy to clipboard operation
OmniMarkupPreviewer copied to clipboard

fix: no need to encode arguments in python 3.x

Open ansiz opened this issue 7 years ago • 7 comments

It seems there is no need to encode arguments in python 3.x, it reports errors on Windows while I set "browser_command": ["C:\Program Files (x86)\Google\Chrome\Application\chrome.exe","{url}"],:

OmniMarkupPreviewer: [ERROR] Error while launching user defined web browser
  Traceback (most recent call last):
    File "C:\Users\Ansiz\AppData\Roaming\Sublime Text 3\Packages\OmniMarkupPreviewer\OmniMarkupPreviewer.py", line 81, in launching_web_browser_for_url
    subprocess.Popen(browser_command)
    File "./python3.3/subprocess.py", line 819, in __init__
    File "./python3.3/subprocess.py", line 1063, in _execute_child
    File "./python3.3/subprocess.py", line 632, in list2cmdline
  TypeError: Type str doesn't support the buffer API

ansiz avatar Jun 25 '17 14:06 ansiz

I have the same problem. Have you solved it?

duoluoxiaosheng avatar Apr 16 '19 08:04 duoluoxiaosheng

I have the same problem. Have you solved it?

yep, just modify the file as I commited

ansiz avatar Apr 16 '19 09:04 ansiz

It dosen't work!
My system is Windows 10
2

1

duoluoxiaosheng avatar Apr 16 '19 10:04 duoluoxiaosheng

@duoluoxiaosheng 把你修改过的代码发来看一下吧,看看第80行报错的代码是什么内容

ansiz avatar Apr 16 '19 10:04 ansiz

我只是在用户配置文件添加了"browser_command"
并没有修改程序文件

def launching_web_browser_for_url(url, success_msg_default=None, success_msg_user=None):
    try:
        setting = Setting.instance()
        if setting.browser_command:
            browser_command = [os.path.expandvars(arg).format(url=url)
                               for arg in setting.browser_command]

            if os.name == 'nt':
                # unicode arguments broken under windows
                encoding = locale.getpreferredencoding()
                browser_command = [arg.encode(encoding) for arg in browser_command]

            subprocess.Popen(browser_command)
            if success_msg_user:
                sublime.status_message(success_msg_user)
        else:
            # Default web browser
            desktop.open(url)
            if success_msg_default:
                sublime.status_message(success_msg_default)
    except:
        if setting.browser_command:
            log.exception('Error while launching user defined web browser')
        else:
            log.exception('Error while launching default web browser')

第80行就是 subprocess.Popen(browser_command)

其中subprocessimport 的一个包

duoluoxiaosheng avatar Apr 16 '19 11:04 duoluoxiaosheng

@duoluoxiaosheng 那你自己改一下吧,我写得很清楚呀,需要修改的地方在我提交的文件中,你照着改那么一行就行了

ansiz avatar Apr 16 '19 11:04 ansiz

好了,可以了,谢谢你

duoluoxiaosheng avatar Apr 17 '19 01:04 duoluoxiaosheng