tchellomello / python-amcrest

A Python 2.7/3.x module for Amcrest and Dahua Cameras using the SDK HTTP API.
GNU General Public License v2.0
216 stars 76 forks source link

python-amcrest triggers a DNS lookup for every command #237

Open dunedain289 opened 3 months ago

dunedain289 commented 3 months ago

I'm using the HomeAssistant Amcrest integration, and my OPNsense router was showing 10000's of queries for my camera DNS names. My cameras have static DHCP assignments, which puts the hostname in Unbound with a 3600s TTL. I expected to see maybe 100 queries per day, but HA was generating ~300 queries per second to the camera names. Changing my HA config to IP addresses solved the problem, and I'm not seeing constant queries.

I think requests is triggering a new DNS lookup every time through this function/loop (i.e. for every single command):

https://github.com/tchellomello/python-amcrest/blob/master/src/amcrest/http.py#L290-L304

Caching the session between calls might help, but I'm not enough of a requests expert to be certain.