mcguirepr89 / BirdNET-Pi

A realtime acoustic bird classification system for the Raspberry Pi 4B, 3B+, and 0W2 built on the TFLite version of BirdNET.
Other
1.31k stars 139 forks source link

FLICKR_API_KEY not found in MQTT Notification settings #968

Open RossiLorenzo opened 1 year ago

RossiLorenzo commented 1 year ago

Hi,

First of all, amazing work! Love this project and all you are doing!

In terms of my issue, I consistently (even after reboots - pulls for new commits) get the following error from the notification system every time a new detection happens. This stops the system and creates long queues of files. I can only restart the analysis by restarting services (and by not receiving the mqtt notification).

09:27:42---WRITING RESULTS TO BirdSongs/July-2023/04-Tuesday/2023-07-04-birdnet-08:24:46.wav.csv ... DONE! WROTE 0 RESULTS.
09:27:43---READING AUDIO DATA... DONE! READ 20 CHUNKS.
09:27:43---Date-time: 2023-07-04 08:25:47
09:27:49---ANALYZING AUDIO... Exception in thread Thread-20:
09:27:49---Traceback (most recent call last):
09:27:49---  File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
09:27:49---    self.run()
09:27:49---  File "/usr/lib/python3.9/threading.py", line 892, in run
09:27:49---    self._target(*self._args, **self._kwargs)
09:27:49---  File "/usr/local/bin/server.py", line 523, in handle_client
09:27:49---    sendAppriseNotifications(species,
09:27:49---  File "BirdNET-Pi/scripts/utils/notifications.py", line 84, in sendAppriseNotifications
09:27:49---    if len(settings_dict.get('FLICKR_API_KEY')) > 0 and "$flickrimage" in body:
09:27:49---TypeError: argument of type 'NoneType' is not iterable

I ran cat ~/BirdNET-Pi/birdnet.conf | grep APPRISE and this is my configuration:

APPRISE_NOTIFICATION_TITLE=""
APPRISE_NOTIFICATION_BODY='{"sciname": "$sciname", "comname": "$comname", "confidence": "$confidence", "audio": "$listenurl", "image": "$flickrimage", "time": "$time"}'
APPRISE_NOTIFY_EACH_DETECTION=1
APPRISE_NOTIFY_NEW_SPECIES=0
APPRISE_WEEKLY_REPORT=0
APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY=0
APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES=0
APPRISE_ONLY_NOTIFY_SPECIES_NAMES=""
APPRISE_ONLY_NOTIFY_SPECIES_NAMES_2=""

and I do have a flickr api key set in there too (FLICKR_API_KEY=....).

Testing MQTT notifications straight from the interface works without any issue, the notification get sent (and received) correctly, it's only during "normal" running that it returns the above error.

I also went on line 523 of handle_client and seen the thisrun.txt file is where settings are loaded from. This is what I got in that file:

SITE_NAME="birdnet"
LATITUDE={MYLAT}
LONGITUDE={MYLONG}
MODEL=BirdNET_GLOBAL_6K_V2.4_Model_FP16
SF_THRESH=0.03
BIRDWEATHER_ID=
CADDY_PWD=
ICE_PWD=birdnetpi
BIRDNETPI_URL=
RTSP_STREAM=
APPRISE_NOTIFICATION_TITLE=""
APPRISE_NOTIFY_EACH_DETECTION=1
APPRISE_NOTIFY_NEW_SPECIES=0
APPRISE_WEEKLY_REPORT=0
APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY=0
APPRISE_MINIMUM_SECONDS_BETWEEN_NOTIFICATIONS_PER_SPECIES=0
APPRISE_ONLY_NOTIFY_SPECIES_NAMES=""
FLICKR_API_KEY={MYAPYKEYCORRECTLYDISPLAYEDHERE}
FLICKR_FILTER_EMAIL=
RECS_DIR=/home/pi/BirdSongs
REC_CARD=default
PROCESSED=/home/pi/BirdSongs/Processed
EXTRACTED=/home/pi/BirdSongs/Extracted
OVERLAP=0.0
CONFIDENCE=0.75
SENSITIVITY=1.25
FREQSHIFT_TOOL=sox
FREQSHIFT_HI=6000
FREQSHIFT_LO=3000
FREQSHIFT_PITCH=-1500
CHANNELS=2
FULL_DISK=purge
PRIVACY_THRESHOLD=0
RECORDING_LENGTH=60
EXTRACTION_LENGTH=
AUDIOFMT=mp3
DATABASE_LANG=en
HEARTBEAT_URL=
SILENCE_UPDATE_INDICATOR=0
RAW_SPECTROGRAM=1
CUSTOM_IMAGE=
CUSTOM_IMAGE_TITLE=""
LAST_RUN=
THIS_RUN=
IDFILE=/home/pi/BirdNET-Pi/IdentifiedSoFar.txt
RTSP_STREAM_TO_LIVESTREAM="0"
ACTIVATE_FREQSHIFT_IN_LIVESTREAM="false"
FREQSHIFT_RECONNECT_DELAY=4000
APPRISE_ONLY_NOTIFY_SPECIES_NAMES_2=""
LogLevel_BirdnetRecordingService="error"
LogLevel_LiveAudioStreamService="error"
LogLevel_SpectrogramViewerService="error"

Let me know if there is any other debugging info I could provide

ehpersonal38 commented 1 year ago

The problem seems to be that your APPRISE_NOTIFICATION_BODY variable in birdnet.conf has weird special characters and symbols in it, which is rejected by the script that copies each line of birdnet.conf to scripts/thisrun.txt. Thus, APPRISE_NOTIFICATION_BODY is missing from scripts/thisrun.txt and makes a NoneType error when the non-existent variable is accessed.

A quick fix will be to edit this line of server.py and change /BirdNET-Pi/scripts/thisrun.txt to /BirdNET-Pi/birdnet.conf. Then just add scripts/server.py to ~/BirdNET-Pi/.gitignore so your server.py doesn't get overwritten when you update.