[英]Unexpected Indent Python error
So whenever i use my cog i get the "Unexpected Indentation" error.. 因此,每当我使用我的齿轮时,我都会收到“意外缩进”错误。
I've been trying to fix it for a while now but it STILL doesn't seem to work.. 我一直试图修复它一段时间但它仍然似乎不起作用..
Code: 码:
@commands.command(pass_context=True)
async def magik(self, ctx, url, url2=None):
"""Apply magik to Image(s)\n .magik image_url or .magik image_url image_url_2"""
try:
print(url)
extensions = ['.png', '.jpg', '.jpeg', '.JPG', '.PNG', '.JPEG']
if any(x in url for x in extensions) and url2 is None:
await self.bot.say("ok, applying magik")
with aiohttp.ClientSession() as session:
location = '/root/discord/files/magik.jpg'
async with session.get(url) as resp:
data = await resp.read()
with open(location, "wb") as f:
f.write(data)
elif url2 is not None and any(x in url2 for x in extensions):
await self.bot.say("ok, applying magik")
with aiohttp.ClientSession() as session:
location = '/root/discord/files/magik.jpg'
location2 = '/root/discord/files/magik2.jpg'
async with session.get(url) as resp:
data = await resp.read()
with open(location, "wb") as f:
f.write(data)
async with session.get(url2) as resp:
data = await resp.read()
with open(location2, "wb") as f:
f.write(data)
else:
await self.bot.say("Not an image!")
return
exif = {}
image = wand.image.Image(filename='/root/discord/files/magik.jpg')
exif.update((k[5:], v) for k, v in image.metadata.items()
if k.startswith('exif:'))
if url2 is not None:
exif2 = {}
image2 = wand.image.Image(filename='/root/discord/files/magik2.jpg')
exif2.update((k[5:], v) for k, v in image2.metadata.items()
if k.startswith('exif:'))
img = wand.image.Image(filename='/root/discord/files/magik.jpg')
print(img.size)
i = img.clone()
r = random.randint(1,4)
if url2 is not None:
with wand.image.Image(filename='/root/discord/files/magik2.jpg') as B:
B.clone()
B.liquid_rescale(width=int(B.width*0.5), height=int(B.height*0.5), delta_x=1, rigidity=0)
B.liquid_rescale(width=int(B.width*1.5), height=int(B.height*1.5), delta_x=2, rigidity=0)
with wand.image.Image(filename='/root/discord/files/magik.jpg') as A:
A.clone()
A.transform(resize='800x800>')
A.liquid_rescale(width=int(A.width*0.5), height=int(A.height*0.5), delta_x=1, rigidity=0)
A.liquid_rescale(width=int(A.width*1.5), height=int(A.height*1.5), delta_x=2, rigidity=0)
A.resize(A.width, A.height)
A.composite_channel('default_channels', A, 'over', 0, 0 )
A.composite_channel('default_channels', B, 'over', 0, 0 )
A.save(filename='/root/discord/files/magik_.png')
else:
params = random.uniform(0.5, 2)
i.transform(resize='800x800>')
i.liquid_rescale(width=int(i.width*0.5), height=int(i.height*0.5), delta_x=1, rigidity=0)
i.liquid_rescale(width=int(i.width*1.5), height=int(i.height*1.5), delta_x=2, rigidity=0)
i.resize(i.width, i.height)
# i.rotate(90 * r)
# i.negate()
i.save(filename='/root/discord/files/magik_.png')
print(exif)
if len(str(exif)) <= 2000 and url2 is None:
await self.bot.say("Exif Data: ```{0}```".format(str(exif)))
elif url2 is not None and len(str(exif)) <= 2000 and len(str(exif2)) <= 2000:
await self.bot.say("Exif Data Image 1: ```{0}```".format(str(exif)))
await self.bot.say("Exif Data Image 2: ```{0}```".format(str(exif2)))
else:
await self.bot.say("Exif Data too long, truncated")
await self.bot.send_file(ctx.message.channel, '/root/discord/files/magik_.png')
except Exception as e:
await self.bot.say(code.format(type(e).__name__ + ': ' + str(e)))
Help is appreciated as i can't seem to fix this error. 感谢帮助,因为我似乎无法解决此错误。
It is likely a problem of using mixed tabs and spaces. 这可能是使用混合制表符和空格的问题。 Depending on the editor you are using, you may have to go to your editor preferences and establish a means to setup "tabs as spaces". 根据您使用的编辑器,您可能必须转到编辑器首选项并建立一种方法来将“选项卡设置为空格”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.