Python 解码subprocess.Popen并存储在文件中

Python 解码subprocess.Popen并存储在文件中,python,subprocess,decode,encode,popen,Python,Subprocess,Decode,Encode,Popen,我为pyLoad编写了一个脚本/插件 基本上,它使用参数执行FileBot 我试图做的是获取输出并将其存储到pyLoad日志文件中 到目前为止还不错。它一直工作到需要解码单个字符为止 UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3 in position 5: ordinal not in range(128) 我不知道怎么做。 我希望你们能帮忙 try: if self.getConfig('outpu

我为pyLoad编写了一个脚本/插件

基本上,它使用参数执行FileBot

我试图做的是获取输出并将其存储到pyLoad日志文件中

到目前为止还不错。它一直工作到需要解码单个字符为止

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3 in position 5: ordinal not in range(128)
我不知道怎么做。 我希望你们能帮忙

    try:
        if self.getConfig('output_to_log') is True:
            log = open('Logs/log.txt', 'a')
            subprocess.Popen(args, stdout=log, stderr=log, bufsize=-1)
提前谢谢

[编辑]

28.05.2015 12:34:06 DEBUG     FileBot-Hook: MKV-Checkup (package_extracted)
28.05.2015 12:34:06 DEBUG     Hier sind keine Archive
28.05.2015 12:34:06 INFO      FileBot: executed
28.05.2015 12:34:06 INFO      FileBot: cleaning
Locking /usr/share/filebot/data/logs/amc.log
Done ヾ(@⌒ー⌒@)ノ
Parameter: exec = cd / && ./filebot.sh "{file}"
Parameter: clean = y
Parameter: skipExtract = y
Parameter: reportError = n
Parameter: storeReport = n
Parameter: artwork = n
Parameter: subtitles = de
Parameter: movieFormat = /mnt/HD/Medien/Movies/{n} ({y})/{n} ({y})
Parameter: seriesFormat = /mnt/HD/Medien/TV Shows/{n}/Season {s.pad(2)}/{n} - {s00e00} - {t}
Parameter: extras = n
所以我猜这个

Done ヾ(@⌒ー⌒@)ノ
是什么导致了这个问题

当我在webgui上打开LogiInterface以查看日志时—这是回溯

Traceback (most recent call last):
  File "/usr/share/pyload/module/lib/bottle.py", line 733, in _handle
    return route.call(**args)
  File "/usr/share/pyload/module/lib/bottle.py", line 1448, in wrapper
    rv = callback(*a, **ka)
  File "/usr/share/pyload/module/web/utils.py", line 113, in _view
    return func(*args, **kwargs)
  File "/usr/share/pyload/module/web/pyload_app.py", line 464, in logs
    [pre_processor])
  File "/usr/share/pyload/module/web/utils.py", line 30, in render_to_response
    return t.render(**args)
  File "/usr/share/pyload/module/lib/jinja2/environment.py", line 891, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/share/pyload/module/web/templates/Next/logs.html", line 1, in top-level template code
    {% extends 'Next/base.html' %}
  File "/usr/share/pyload/module/web/templates/Next/base.html", line 179, in top-level template code
    {% block content %}
  File "/usr/share/pyload/module/web/templates/Next/logs.html", line 30, in block "content"
    <tr><td class="logline">{{line.line}}</td><td>{{line.date}}</td><td class="loglevel">{{line.level}}</td><td>{{line.message}}</td></tr>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3 in position 5: ordinal not in range(128)
回溯(最近一次呼叫最后一次):
文件“/usr/share/pyload/module/lib/battle.py”,第733行,在U形手柄中
返回路线。呼叫(**args)
包装器中的文件“/usr/share/pyload/module/lib/battle.py”,第1448行
rv=回拨(*a,**ka)
文件“/usr/share/pyload/module/web/utils.py”,第113行,在视图中
返回函数(*args,**kwargs)
文件“/usr/share/pyload/module/web/pyload_app.py”,第464行,在日志中
[前置处理器])
文件“/usr/share/pyload/module/web/utils.py”,第30行,在render\u to\u响应中
返回t.render(**args)
文件“/usr/share/pyload/module/lib/jinja2/environment.py”,第891行,在渲染中
返回self.environment.handle\u异常(exc\u info,True)
顶级模板代码中的文件“/usr/share/pyload/module/web/templates/Next/logs.html”,第1行
{%extends'Next/base.html%}
顶级模板代码中的文件“/usr/share/pyload/module/web/templates/Next/base.html”,第179行
{%block content%}
文件“/usr/share/pyload/module/web/templates/Next/logs.html”,第30行,在“内容”块中
{{line.line}{{line.date}{{{line.level}}{{line.message}
UnicodeDecodeError:“ascii”编解码器无法解码位置5中的字节0xe3:序号不在范围内(128)
我找到了一个解决方案

        proc=subprocess.Popen(args, stdout=subprocess.PIPE)
        for line in proc.stdout:
            self.logInfo(line.decode('utf-8').rstrip('\r|\n'))
        proc.wait()

您能否发布完整的回溯,以便我们准确地知道哪一行抛出了错误?请将
#-*-编码:utf-8-*-
放在Python脚本的顶部,看看它是否有帮助