diyhue / diyHue

Main diyHue software repo
https://diyhue.org/
Other
1.52k stars 274 forks source link

Container does not start when GitHub API limit reached: updateManager.py line 50 undefined publish_time. #1019

Open rossowl opened 1 month ago

rossowl commented 1 month ago

Issue does not already exist?

I have searched and found no existing issue

Select Environment

Docker

Home Assistant related?

No

Description

UnboundLocalError: cannot access local variable 'publish_time' where it is not associated with a value

logging.info("publish_time diyHue : " + str(publish_time))

GitHub API: {"message":"API rate limit exceeded for .....

Errorlog:

`2024-06-01 13:23:21,617 - services.updateManager - INFO - creation_time diyHue : 2024-05-28 19

Traceback (most recent call last):

File "/opt/hue-emulator/HueEmulator3.py", line 115, in

updateManager.startupCheck()

File "/opt/hue-emulator/services/updateManager.py", line 110, in startupCheck

githubCheck()

File "/opt/hue-emulator/services/updateManager.py", line 50, in githubCheck

logging.info("publish_time  diyHue : " + str(publish_time))

                                             ^^^^^^^^^^^^

UnboundLocalError: cannot access local variable 'publish_time' where it is not associated with a value

Exception ignored in: <function Group.del at 0xf67ec5c8>

Traceback (most recent call last):

File "/opt/hue-emulator/HueObjects/init.py", line 1051, in del

ImportError: sys.meta_path is None, Python is likely shutting down`

Steps to reproduce

start container

Please enter your operating system details here

Debian

What DiyHue version(branch) are you using?

master (latest)

hendriksen-mark commented 3 weeks ago

Hi,

Do you still have this problem? This is not a diyhue issue. Github limits the request per hour per user. https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28

How did you get this error to occur? The rate limit is 60 request per hour.

Mark

GitHub Docs
Rate limits for the REST API - GitHub Docs
Learn about REST API rate limits, how to avoid exceeding them, and what to do if you do exceed them.
rossowl commented 3 weeks ago

I had hass rest sensor for zigbee2mqtt latest version with frequency 30 sec. After half of every hour github returns message with status code != 200. The is publish_time undefined.

def githubCheck(): creation_time = subprocess.run("stat -c %y HueEmulator3.py", shell=True, capture_output=True, text=True)#2024-02-18 19:50:15.000000000 +0100\n

#...
response = requests.get(url)

# status code is not 200, this code is skipped
if response.status_code == 200:
    #...
    device_data = json.loads(response.text)

    # here is publish_time defined but only if status_code == 200
    publish_time = datetime.strptime(device_data["commit"]["commit"]["author"]["date"], "%Y-%m-%dT%H:%M:%SZ").strftime("%Y-%m-%d %H")
    # end of skipped code when status code != 200

# this line is always processed
logging.info("creation_time diyHue : " + str(creation_time))

status code != 200 and publish_time is not defined. This line raise Exception

logging.info("publish_time  diyHue : " + str(publish_time))
mariusmotea commented 3 weeks ago

I think it is now fixed