pi-hole / web

Pi-hole Dashboard for stats and more
https://pi-hole.net
Other
2.05k stars 559 forks source link

Problems with PiOLED and PiTFT since the last update #2467

Closed Falconcrest closed 1 year ago

Falconcrest commented 1 year ago

Hello,

since the last update, the displays of 2 Pi-hole with PiOLED and PiTFT are black. Pi-hole data is no longer displayed. I set up both displays a while ago following the instructions below:

https://learn.adafruit.com/pi-hole-ad-blocker-with-pi-zero-w/install-pioled https://learn.adafruit.com/pi-hole-ad-blocker-with-pi-zero-w/install-mini-pitft

If I run the command sudo python3 stats.py once on the Pi-hole with PiTFT I get the following output:

root@pihole-backup-I:/home/dietpi# sudo python3 stats.py Traceback (most recent call last): File "stats.py", line 109, in DNSQUERIES = data['dns_queries_today'] TypeError: list indices must be integers or slices, not str

and on the Pi-Hole with PiOLED I get the following output:

root@pihole-backup-II:~# sudo python3 stats.py Traceback (most recent call last): File "/root/stats.py", line 96, in DNSQUERIES = data['dns_queries_today'] TypeError: list indices must be integers or slices, not str

Excerpts from both relevant lines of the respective stats.py:

PiTFT stats.py

# Pi Hole data!
try:
    r = requests.get(api_url)
    data = json.loads(r.text)
    DNSQUERIES = data['dns_queries_today'] **#line 109 !**
    ADSBLOCKED = data['ads_blocked_today']
    CLIENTS = data['unique_clients']
except KeyError:
    time.sleep(1)
    continue

PiOLED stats.py

# Pi Hole data!
try:
    r = requests.get(api_url)
    data = json.loads(r.text)
    DNSQUERIES = data['dns_queries_today'] **#line109 !**
    ADSBLOCKED = data['ads_blocked_today']
    CLIENTS = data['unique_clients']
except KeyError:
    time.sleep(1)
    continue

Can the error be due to the changes in Pi-hole FTL?

DL6ER commented 1 year ago

This is caused by https://github.com/pi-hole/AdminLTE/pull/2411 see also our announcement in November about this upcoming change: https://pi-hole.net/blog/2022/11/17/upcoming-changes-authentication-for-more-api-endpoints-required/

There you can also find a description how to fix your scripts.

Falconcrest commented 1 year ago

Thank you for the info.

Since another Pi-hole with TFT and PADD does not show any problems in this regard, I can assume that the necessary adjustments have already been made to padd.sh?

yubiuser commented 1 year ago

PADD does not query the web API, but directly FTL's telnet API.

Falconcrest commented 1 year ago

Ok, Thanks.

Since I don't feel able to make these adjustments in the Python script due to a lack of programming knowledge, I have to see if I can find help.

DL6ER commented 1 year ago

The python scripts you are using has requests.get(api_url) - where does this api_url come from?

As mentioned in the blog post, if there is a line like

api_url = "http://pi.hole/admin/api.php?status"

somewhere, you will only have to change this to

api_url = "http://pi.hole/admin/api.php?status&auth=abcdef123456789"

where you can get the actual token (abcdef123456789 is just a placeholder above) from the Pi-hole web interface (see Settings -> API -> Show API token) or by running grep WEBPASSWORD /etc/pihole/setupVars.conf on your Pi-hole.

Falconcrest commented 1 year ago

It doesn't seem to be that difficult normally, but...

Here are a few lines that might apply:

-# Import Python Imaging Library from PIL import Image, ImageDraw, ImageFont

api_url = 'http://localhost/admin/api.php'

If I replace this line with

api_url = 'http://localhost/admin/api.php?status&auth=abcdef123456789'

then unfortunately it still doesn't work. Of course I replaced with my token, also the <"> with <'>, because that's how it is in the original script.

yubiuser commented 1 year ago

Can you access the data if you open the URL in your bowser (if you are not logged-in the web dashboard)?

Falconcrest commented 1 year ago

Yes, data is displayed. For output I used the browser on my PC. When I enter http://10.0.0.XXX/admin/api.php with the password disabled, it shows:

JSON domains_being_blocked: 12345 dns_queries_today: 38 . . . status: "enabled"

If I enter http://10.0.0.XXX/admin/api.php?status&auth=abcdef123456789 with an active password then only appears

JSON status: "enabled"

DL6ER commented 1 year ago

Sorry, the confusion comes from that you called api.php before and explicitly ask for ?status now. However, the status call does not include what you want so you should actually either be using

api_url = 'http://localhost/admin/api.php?auth=abcdef123456789'

(as before with added auth=...)

or

api_url = 'http://localhost/admin/api.php?summary&auth=abcdef123456789'

(being fully explicit).

Both should return identical information.

Falconcrest commented 1 year ago

api_url = 'http://localhost/admin/api.php?summary&auth=abcdef123456789'

was the solution! That's how it works. I thank you for the great support.

Falconcrest commented 1 year ago

I now have the same problem with accessing the api_url with an RPi Zero W and an e-Paper Display. Well, I've already learned a lot about it from this post here, but the solution, once again, isn't that easy for me.

The e-paper is addressed using the pihole-dashboard. https://github.com/santoru/pihole-dashboard

I temporarily disabled the password and it works so far, it is of course better with an activated password. I think, I found the corresponding line in the init.py file, but I haven't been able to create the correct entry so far.

def update(): url = "http://127.0.0.1:{}/admin/api.php".format(PIHOLE_PORT) r = json.load(urllib.request.urlopen(url))

Both of the variants shown here do not work that way.

I also contacted the developer at https://github.com/santoru/pihole-dashboard/issues/9

DL6ER commented 1 year ago

It should be something like

def update():
    url = "http://127.0.0.1:{}/admin/api.php?summaryRaw&auth=abcdef123456789".format(PIHOLE_PORT)
    r = json.load(urllib.request.urlopen(url))

but this isn't the best way of doing this (the password hash should be a variable as well).

rdwebdesign commented 1 year ago

I think this should work (untested - I usually don't work with Python):

madryboy commented 1 year ago

Hello I also updated and was unable to view anything on the e-ink screen so I went through and attempted to follow the changed made by the posts above by adding the necessary token keys into the stats script but now for some reason I get this error Traceback (most recent call last): File "/home/pi/python/stats.py", line 67, in draw.text((x, top), "HOST: " + HOST, font=font, fill=fill_color) TypeError: can only concatenate str (not "bytes") to str

update: a friend of mine said that changing line 67 from
draw.text((x, top), "HOST: " + HOST, font=font, fill=fill_color) to draw.text((x, top), "HOST: " + str(HOST), font=font, fill=fill_color) but I noticed when I ran the script it appeared to work but there appears to be random /B and N characters so im not to sure this is the most efficient or correct way of doing this

any help is much appreciated also if I am posting in the wrong section my apologies I just found this as the most relevant

rdwebdesign commented 1 year ago

Your error is happening on a third party app, not developed by Pi-hole.

If none of the above suggestions work for you, please ask your question to the app developers.

Falconcrest commented 1 year ago

@DL6ER , @rdwebdesign

Sorry I haven't responded to your tips yet, but this pi-hole isn't on site. But I think I'll test it this week.

Falconcrest commented 1 year ago

I think this should work (untested - I usually don't work with Python):

* around line 35, add `PIHOLE_APITOKEN`:
  ```python
  PIHOLE_PORT = 80
  PIHOLE_APITOKEN = "abcdef123456789"
  ```

* Inside the `update()` function, add `?summaryRaw&auth={}` to the URL and add `PIHOLE_APITOKEN` to `.format()`
  ```python
  def update():
      url = "http://127.0.0.1:{}/admin/api.php?summaryRaw&auth={}".format(PIHOLE_PORT, PIHOLE_APITOKEN)
      r = json.load(urllib.request.urlopen(url))
  ```

I have now entered everything as described, unfortunately I get the following error message:

pi@alpenblick:~/pihole-dashboard/pihole_dashboard $ python3 __init__.py
   File "/home/pi/pihole-dashboard/pihole_dashboard/__init__.py", line 86
     try:
         ^
IndentationError: unindent does not match any outer indentation level
rdwebdesign commented 1 year ago

As I said, this was not tested.

Also note: this is an external app. Please, ask for help here: https://github.com/santoru/pihole-dashboard