L
L
L1MO2021-11-05 22:23:25
Python
L1MO, 2021-11-05 22:23:25

Python code not working, what should I do?

There is this code:

from pyrogram import Client
import time

i = 1


api_id = id
api_hash = "hash"

with Client("my_account", api_id, api_hash) as app:

while True:
    try:
    if i <= 68:
    app.set_profile_photo(photo = "C:/Users/Block/Desktop/cat/f{i}.jpg")
i += 1
time.sleep(10)
else :
    i = 1
except:
    continue


What to do?
Mistake:
C:\Users\Block\Desktop\Change-Avata>py main.py
File "main.py", line 12
while True:
^
IndentationError: expected an indented block

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Gornostaev, 2021-11-05
@sergey-gornostaev

Read textbook. At least for dummies of younger preschool age.

C
Collin, 2021-11-05
@Collin

You don't have a block of code after :
tabs Since python doesn't have semicolons or parentheses (mostly), correct tabs are important. Read carefully the errors that the interpreter throws out to you, everything is written there =)
This is how your code should have been:

from pyrogram import Client
import time

i = 1


api_id = id
api_hash = "hash"

with Client("my_account", api_id, api_hash) as app:
    while True:
        try:
            if i <= 68:
                app.set_profile_photo(photo = "C:/Users/Block/Desktop/cat/f{i}.jpg")
                i += 1
                time.sleep(10)
            else :
                i = 1
        except:
            continue

Well... or like this:
from pyrogram import Client
import time

api_id = id
api_hash = "hash"

with Client("my_account", api_id, api_hash) as app:
    for i in range(68):
        try:
            app.set_profile_photo(photo = "C:/Users/Block/Desktop/cat/f{i}.jpg")
            time.sleep(10)
        except:
            continue

Why do you really need a try except block here, I don't quite understand if you don't handle the error. It's better to get rid of it altogether.
from pyrogram import Client
import time

api_id = id
api_hash = "hash"

with Client("my_account", api_id, api_hash) as app:
    for i in range(68):
        app.set_profile_photo(photo = "C:/Users/Block/Desktop/cat/f{i}.jpg")
        time.sleep(10)

V
Vasily Bannikov, 2021-11-05
@vabka

You clearly wrote that the indent is not enough.
A little higher you have with - after it there should be indents.
Similarly with try-except a little further and if

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question