0
我开始尝试Python,我不明白我的代码有什么问题...我得到: 我得到一个错误的第86行和第34行,说TypeErroe:不支持的操作数类型为+:'NoneType'和'str'python2 :: TypeError:不支持的操作数类型为+:'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}`);
});
从错误中看起来像,logo是无对象。在传递给函数构建之前,打印args.logo的值。检查它是否指向无。你也可以检查这个链接的更多信息无https://stackoverflow.com/questions/21095654/what-is-a-nonetype-object – Varun
我认为这是网址'&' – XiaoHu