New to python, so it's probably something simple. Raspberry Pi 4, with apache running and CGI wired up. Speedtest-cli is installed and working fine. I can run the script below in Putty with no issues. But when I try to run it in cgi-bin for a test, I get an error on this line:
print ping.group(1)
Error: <type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'group'
It seems to be skipping over the line where speedtest is called: response = subprocess.Popen('/usr/bin/speedtest', shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8')
Again, this is working fine in Putty.
#!/usr/bin/python
print ('Content-Type: text/html')
print
import os
import re
import subprocess
import time
import cgi, cgitb
cgitb.enable()
try:
while(True):
print("\rGetting data")
print("------------------------------------")
response = subprocess.Popen('/usr/bin/speedtest', shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8')
#print(response)
ping = re.search("Latency:\s+(.*?)\s+", response, re.MULTILINE)
download = re.search("Download:\s+(.*?)\s", response, re.MULTILINE)
upload = re.search("Upload:\s+(.*?)\s", response, re.MULTILINE)
ping = ping.group(1)
download = download.group(1)
upload = upload.group(1)
print("Ping: " + ping + " m/s")
print("Download: " + download + " mb/s")
print("Upload: " + upload + " mb/s")
time.sleep(1810)
print("\r\n\r\n")
except:
cgitb.handler()