Jmeter+Python-1:问题记录,jmeter执行Python3的脚本时报 ValueError: chr() arg not in range(256)

报错脚本内容:

# -*- coding:utf-8 -*-
import html

class OutputResult():

    def __init__(self,fretMsg):
        self.fretMsg = fretMsg

    #将fretMsg反转义,也就是报错部分
    def plainTextToHtml(self):
        self.fretMsg1 = html.unescape(self.fretMsg)
        return  self.fretMsg1

报错原因解析:Python的JSR223 Sampler中选择的语言是“jython2.7.2”,不支持Python3中的反转义方法

Jmeter+Python-1:问题记录,jmeter执行Python3的脚本时报 ValueError: chr() arg not in range(256)_第1张图片

解决方法:脚本改成以下内容

import HTMLParser #python2的反转义方法在此模块中

class OutputResult():

    def __init__(self,fretMsg):
        self.fretMsg = fretMsg

    #将fretMsg反转义处理
    def plainTextToHtml(self):
        self.fretMsg1 = HTMLParser.HTMLParser().unescape(self.fretMsg)
        return  self.fretMsg1

你可能感兴趣的:(Jmeter)