3 回答
TA贡献1827条经验 获得超8个赞
try期望except它后面跟着一个块。
您可以按如下方式修改您的代码:
def funt():
print(Fore.GREEN, end='')
tool = input('Enter Desired Tool: ')
if tool == 'web':
try:
print(Fore.CYAN, end='')
site = input('Please Enter The Website Here: ')
response = requests.get(site)
requests.get(site)
if response.status_code == 200:
print(f'{Fore.GREEN}Online!')
sleep(1)
else:
print(f'{Fore.RED}Offline!')
sleep(1)
except:
pass
while True:
funt()
但是编写正确的代码需要您处理异常。所以,如果可能的话,在块中写一段代码except。
TA贡献1780条经验 获得超4个赞
做这个:
def funt():
print(Fore.GREEN, end='')
tool = input('Enter Desired Tool: ')
if tool == 'web':
try:
print(Fore.CYAN, end='')
site = input('Please Enter The Website Here: ')
response = requests.get(site)
requests.get(site)
if response.status_code == 200:
print(f'{Fore.GREEN}Online!')
sleep(1)
else:
print(f'{Fore.RED}Offline!')
sleep(1)
# You were missing this part:
except:
print("Message")
while True:
funt()
try块总是与块一起出现catch。try 块的目的是尝试运行可能throw带有exception. 该catch块是捕获此异常的内容。
添加回答
举报