在python 2.7上使用pyshark遇到lxml.etree.XMLSyntaxError

时间:2016-03-16 07:48:36

标签: python-2.7 pyshark

这是一个用python编写的简单脚本,我可以在Linux上正常运行它。但当我把它移到Windows时,有一个奇怪的错误。我希望有所帮助。

在运行代码之前,我已经为环境做了一些准备:
1.为python 2.7安装Microsoft Visual C ++编译器 2.安装python 2.7.11
3. pip install pyinstaller
4. easy_install pyshark
以下是我的代码的一部分。

# -*- coding: utf-8 -*-
from __future__ import print_function
import pyshark
import lxml
import os

def analysis_method(file_name):
    cap = pyshark.FileCapture(input_file=file_name)
    for packet in cap:
        if hasattr(packet, "http"):
            http_layer = packet["http"]

以下是错误信息:
追溯(最近的呼叫最后):
在analysis_method中文件“packet_offline_analysis.py”,第36行   对于封顶的数据包:
文件“C:\ Python27 \ lib \ site-packages \ pyshark-0.3.6.1-py2.7.egg \ pyshark \ capture \ capture.py”,第173行,在_packets_from_tshark_sync中   self._get_packet_from_stream(tshark_process.stdout,data,psml_structure = psml_structure))
run_until_complete文件“C:\ Python27 \ lib \ site-packages \ trollius-1.0.4-py2.7-win32.egg \ trollius \ base_events.py”,第300行,在run_until_complete中   返回future.result()
文件“C:\ Python27 \ lib \ site-packages \ trollius-1.0.4-py2.7-win32.egg \ trollius \ futures.py”,第287行,结果
  提升self._exception
lxml.etree.XMLSyntaxError:输入不正确的UTF-8,表示编码!
字节:0xD6 0xD0 0xB9 0xFA,第6行,第58列

1 个答案:

答案 0 :(得分:0)

卸载您的中文版Wireshark,并安装英文版的Wireshark。 然后问题就解决了。