python 3不识别类似字节的对象b

时间:2017-01-14 07:46:50

标签: python pygraphviz

我使用的是python 3.4,我尝试使用lib pygraphviz

代码(取自pygraphviz):

def _run_prog(self, prog='nop', args=''):
"""Apply graphviz program to graph and return the result as a string.

>>> A = AGraph()
>>> s = A._run_prog() # doctest: +SKIP
>>> s = A._run_prog(prog='acyclic') # doctest: +SKIP

Use keyword args to add additional arguments to graphviz programs.
"""
    runprog = r'"%s"' % self._get_prog(prog)
    cmd = ' '.join([runprog, args])
    dotargs = shlex.split(cmd)
    p = subprocess.Popen(dotargs,
                         shell=False,
                         stdin=subprocess.PIPE,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE,
                         close_fds=False)
    (child_stdin,
     child_stdout,
     child_stderr) = (p.stdin, p.stdout, p.stderr)
    # Use threading to avoid blocking
    data = []
    errors = []
    threads = [PipeReader(data, child_stdout),
               PipeReader(errors, child_stderr)]
    for t in threads:
        t.start()

    self.write(child_stdin)
    child_stdin.close()

    for t in threads:
        t.join()

    if not data:
        raise IOError(b"".join(errors))

    if len(errors) > 0:
        warnings.warn(b"".join(errors), RuntimeWarning)

    return b"".join(data)

跑步时我遇到了这个奇怪的错误:

Traceback (most recent call last):
  File "main.py", line 39, in <module>
    g.draw(filename=args.out)
  File "/home/moshe/Desktop/boaz_matala_3_mivne/code/PcapViz-master/pcapviz/core.py", line 142, in draw
    graph.draw(filename)
  File "/usr/local/lib/python3.4/dist-packages/pygraphviz/agraph.py", line 1474, in draw
    data = self._run_prog(prog, args)
  File "/usr/local/lib/python3.4/dist-packages/pygraphviz/agraph.py", line 1338, in _run_prog
    warnings.warn(b"".join(errors), RuntimeWarning)
TypeError: can't use a string pattern on a bytes-like object

虽然我用b来表示类似字节的对象。

我做错了什么? 感谢。

0 个答案:

没有答案