【发布时间】:2021-07-12 23:56:52
【问题描述】:
我的代码不起作用,我尝试了很多东西。 我得到这个错误:IndentationError:期望一个缩进块 我希望有一个人可以帮助我。谢谢。
import requests
import threading
url = 'https://example.com'
def do_request():
while True:
response = requests.get(url)
print(response)
threads = []
for i in range(50):
t = threading.Thread(target=do_request)
t.daemon = True
threads.append(t)
for i in range(50):
threads[i].start()
for i in range(50):
threads[i].join()
【问题讨论】:
-
您有一个 while 循环,其中代码没有缩进。还有一个代码没有缩进的 def。这是非常基本的 Python 语法。也许您可以从教程中受益。
-
请阅读How to Ask。始终包含 full 错误消息,而不仅仅是您认为重要的部分。您的错误消息还将包括行号、生成错误的代码和回溯。
-
但是您的
def和while都缺少缩进代码块。
标签: python python-3.x pip