简体   繁体   中英

No module named requests but satisfied on RP OS 64bit

Occasionally my PiHole goes down and I'm unavailable to resolve any sites, it just did it the other day for hours before I noticed.

I'm trying to run this to catch the times that I miss it so it doesn't mess up anything for anyone else on the.network.

For some reason, it's telling me on line 1, no module named Requests when I already have it.

Verified by running pip show requests and it shows version 2.25.1, installed using sudo pip install requests .

I'm running Python 2.7.18. I have another Pi I tested it on which doesn't seem to show any problems but I have omv installed on it so I couldn't test with Pihole without fear of breaking something.

Any advice on how to get the code working? Thanks.

In the end I'm planning to have a cronjob that will start on reboot, launch tmux and run this.

Edit: It looks like I already had requests installed as a dependency for another program.

The location is /home/usr/.local/lib/python3.9/site-packages

import requests
import subprocess
import time

def check_reachability(url):
  try:
    response = requests.get(url)
    if response.status_code == 200:
      return True
    else:
      return False
  except:
    return False

def reboot_pihole():
  subprocess.run(["pihole", "restartdns"])

while True:
  reachable = check_reachability("htts://google.com")
  if not reachable:
    reboot_pihole()
  time.sleep(60) # check every 60 seconds

I solved it by just running

python3 program.py

instead of

python program.py

Edit: The program was written for Python 3 when I have both Python 2.7 and 3 installed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM