【发布时间】:2018-09-02 19:10:07
【问题描述】:
我正在尝试使用 Python 对 URL 进行 API 测试,我有以下代码块
def simple_get(url):
try:
page_response = requests.get(page_link, timeout=5)
if page_response.status_code == 200:
# extract
else:
print(page_response.status_code)
# notify, try again
except requests.Timeout as e:
print("It is time to timeout")
print(str(e))
except # other exception
当我运行它时给我以下错误
File "<ipython-input-16-6291efcb97a0>", line 11
else:
^
IndentationError: expected an indented block
我不明白为什么当我已经缩进了“else”语句时,笔记本仍然要求缩进
【问题讨论】:
-
确保您没有将制表符与空格混用,并按照 python 标准使用 4 个空格缩进
-
if ...:后面需要有一个声明你可以在pass后面加上一个 -
因为你还没有告诉 if 通过。
-
为什么我会得到负分
标签: python if-statement indentation