我正在尝试运行此python代码,但我不断收到错误消息“意外缩进”.我不确定什么是错的.间距似乎很好.有任何想法吗?
services = ['Service1']
for service in services:
try:
print service + '\t',
if 'notavailable' not in requests.get('some website' + service + '&username=' + username, headers={'X-Requested-With': 'XMLHttpRequest'}).text:
print 'Available'
else:
print ''
except Exception as e:
print e
解决方法:
services = [‘Service1’]与for循环不一致.
services = ['Service1']
for service in services: <-- unexpected indentation
只需按如下方式排列代码即可.
services = ['Service1'] # need to line up with loop
for service in services:
try:
print service + '\t',
if 'notavailable' not in requests.get('some website' + service + '&username=' + username, headers={'X-Requested-With': 'XMLHttpRequest'}).text:
print 'Available'
else:
print ''
except Exception as e:
print e
你的代码也是python 2语法而不是python 3
标签:python
来源: https://codeday.me/bug/20190624/1277804.html