Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with a loop
#1
Hey, I'm kinda new to Python and need help with a loop.

I'm calling functions through a website's API, and in order to stay logged in I need to call a request-function every 3rd minute

import requests

LoggedInURL = "https://webpage.com/IsLoggedIn"

LoggedInHeaders = {
    'accept': "application/json",
    'AOToken': MyToken,
    }

LoggedInResponse = requests.request("GET", LoggedInURL, headers=LoggedInHeaders)

print(LoggedInResponse.json())
I want to create a loop where I call LoggedInResponse every third minute. Could it look like this?

import threading

def printit():
  threading.Timer(180, printit).start()
  print(LoggedInResponse)

printit()
Reply
#2
Sure, that'd run once every 3 minutes. But it wouldn't send a request to the server every 3 minutes.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020