-4

My Code is not working, and i tried so many things. I get this Error: IndentationError: expected an indented block I hope someone can help me. Thank you.

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()
  • You have a while loop in which the code is not indented. And a def in which the code is not indented. This is extremely basic Python syntax. Perhaps you could benefit by working through a tutorial. – John Coleman Apr 18 '21 at 16:38
  • 1
    Please read [ask]. Always include the _full_ error message, not just the part you think is important. Your error message will also include a line number, the code generating the error, and a traceback. – ChrisGPT was on strike Apr 18 '21 at 16:38
  • But both your `def` and `while` are lacking indented code blocks here. – ChrisGPT was on strike Apr 18 '21 at 16:38

1 Answers1

0

Well, I believe your problem is rather simple, in that you have forgotten to do what the error tells you: not indented correctly. Correctly indented code:

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()
Alice F
  • 435
  • 5
  • 13