我开始尝试使用Python,但我无法理解代码的错误......我得到了: 我得到了第86行和第34行的错误,其中显示了TypeErroe:不支持的操作数类型+:' NoneType'和' str'
请帮我解决这个问题!
python code.py:
def build(string, path, name, logo=""):
qr = qrcode.QRCode(
version = 2,
error_correction = qrcode.constants.ERROR_CORRECT_H,
box_size = 10,
border = 1
)
qr.add_data(string)
qr.make( fit = True)
img = qr.make_image()
img = img.convert("RGBA")
icon = Image.open(logo+'.png')
img_w, img_h = img.size
factor = 4
size_w = int(img_w / factor)
size_h = int(img_h / factor)
icon_w, icon_h = icon.size
if icon_w > size_w: icon_w = size_w
if icon_h > size_h: icon_h = size_h
icon = icon.resize((icon_w, icon_h), Image.ANTIALIAS)
w = int((img_w - icon_w) / 2)
h = int((img_h - icon_h) / 2)
icon = icon.convert("RGBA")
newimg = Image.new("RGBA", (icon_w + 8, icon_h + 8), (255, 255, 255))
img.paste(newimg, (w-4, h-4), newimg)
img.paste(icon, (w, h), icon)
img.save(path + name + '.png', quality = 100)
file = path + name + '.png'
return file
if __name__ == "__main__":
argparser = argparse.ArgumentParser()
argparser.add_argument('Words')
argparser.add_argument('-d', '--directory', default = os.getcwd())
argparser.add_argument('-n', '--name')
argparser.add_argument('-l', '--logo')
args = argparser.parse_args()
try:
file = build(
args.Words,
args.directory,
args.name,
args.logo
)
print (str(file))
except:
raise
node code.js:
const child = require('child_process');
child.exec('python code.py http://xx.com/down?name=client&type=1&shopId=1001 -n service -l ./img/service -d ./', function (error, stdout, stderr) {
if (error) {
console.log(error.stack);
console.log('Error code: '+error.code);
return;
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
答案 0 :(得分:0)
您的徽标变量似乎是NULL(其中没有值无类型)。首先检查它是否仍为无类型。
if(logo !=None ): # or if logo is not None:
image = logo + '.png'
else:
#put what you want to do
icon = Image.open(image)