Can you post the full script?
bakebit_nanohat_oled.txt (11.2 KB)
Sure. Her’s the one I’m using with dietpi, and trying to modify. You can see the lines I’m trying to add on rows 195-209.
And attached here is the script from my other Unbuntu instance that’s out of date but still works.
bakebit_nanohat_oled_v2.txt (14.0 KB)
I removed the link to the first file, the pihole auth key is visible in there.
I will later check it out.
Oh, thanks, but that was a dummy key I put in there. ![]()
Oh alright, I reverted the deletion ![]()
I tested a bit and found a way to use curl again, I think it has to do with the API changes from pihole, since it’s not possible anymore to get data out of the api without the authentication. (at least I didn’t found a way)
And the “problem” curl has are the special characters in the URL?
So I used -S flag to get error output to see what was happening. It turns out I also had to use --insecure and -L, since my webserver redirects to HTTPS but I have no certificates for 127.0.0.1/localhost nor the LAN IP ![]()
Also I had to set the whole URL in " ", otherwise curl made weird things.
So in the end it works for me from CLI with:
curl --insecure -fsSL "http://localhost/admin/api.php?status&auth=<AUTH_KEY_HERE>"
and I get back {"status":"enabled"}
and sure also stuff like
# curl --insecure -fsSL "http://localhost/admin/api.php?summary&auth=<KEY>" | jq .dns_queries_today
# "17,888"
then I wrote some lines (using ?summaryRaw now and not sure if all imports are necessary here
):
#!/usr/bin/env python
import sys
import os
import subprocess
print( subprocess.check_output('curl --insecure -fsSL "http://localhost/admin/api.php?summaryRaw&auth=<KEY>" | jq .dns_queries_today', shell = True ).strip())
but I get back b'17134' and when I use only ?summary instead of summaryRaw it’s b'"17134'".
When I output it without jq it’s in the format
b'{"option":value,"option":value,......}'
so this means it prints a value type byte isntead of string ![]()
We can fix this with decode()
So the final example script, with clean output, looks like:
#!/usr/bin/env python
import sys
import os
import subprocess
print(subprocess.check_output('curl --insecure -fsSL "http://localhost/admin/api.php?summaryRaw&auth=<KEY>" | jq .dns_queries_today', shell = True ).strip().decode())
Yes sorry, I forgot to mention that I also tried everything with “https” as well but also with no luck. And sorry again, I think I’ve been sending us on a wild goose chase. So I tried implementing your solution above and was still not having any luck. UNTIL…
Mimicking the old python file I was trying to add all of your solutions underneath this “index==1” section here, but no mater what I tried the file would fail:
But I noticed in your small script above that works, the cmd line is right underneath the “import” section of the file. So… I moved all the cmd lines up to that part of the file here, and suddenly stuff started working:
Now this solution doesn’t fully solve the problem, it only works some of the time and still fails intermittently, but it certainly sheds some light on the problem; which I think has been a python syntax/order of operations thing this whole time. I’m going to keep plugging away at this thing until I can get it fully working again and maybe look for some help with the python if I get stuck. Thanks again for all the help.
file for reference:
bakebit_nanohat_oled.txt (12.5 KB)
Alright, finally got everything back up and running, thank you again for all your help.
Here are my files:
EDIT: Pi-hole wasn’t automatically enabling after timer finished, fixed:
bakebit_nanohat_oled.txt (14.8 KB)


And here are some photos of my cool Pi-hole:







