0

I have a python program that probes the spotify API every 5 or 30 seconds (depending on activity) and track the current song I am listening to. Spotify offers no webhook so this is the only method I am left with. The issue is that after 3 or 4+ hours, my wifi cuts out after my request times out. If this happens while it is on sleep, I have to wake it up in order to reset the wifi, otherwise it stays dead.

Here is a reduced version of the code below, tracker is my spotify client object.

while True:
        listining_info, time_string, response = tracker.get_current_track()
        sleep_timer=5

            payload = {
                "song_id": str(listining_info.get("id")),
                "song_name": str(listining_info.get("name")),
                "artisits": str(listining_info.get("artists")),
                "primary_artist": str(listining_info.get("main_artist")),
                "song_length": str(listining_info.get("length")),
                "total_play_count": int(count),
                "current_play_time": str(listining_info.get("position")),
                "pic_link": str(listining_info.get("picture")),
            }

                requests.post(
                    privateinfo.api_host() + "/sptfy_server/",
                    headers={"Content-Type": "application/json; charset=utf-8"},
                    json=payload,
                    timeout=5,
                )
            # count = 0
        time.sleep(sleep_timer)

I've tried increasing the time between requests but that doesn't seem to fix it. I also tried 2 different wifi adapters and both have had this issue although 1 was significantly and noticeably worse. I have yet to try ethernet but was wondering if this was a software error or if anyone else has run into this and how they solved it. And if there is some better way to retrieve live information about the song I am listening to I am also open to that.

  • You could look at answers to [this question](https://stackoverflow.com/q/54479347/2280890) to reconnect your WiFi in the event it disconnects. – import random Oct 27 '22 at 22:16

0 Answers0