0

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()
Greg
  • 747
  • 9
  • 23
  • `re.search("Latency:\s+(.*?)\s+", response, re.MULTILINE)` is returning None, which I believe means that it didn't find a match. Double check `response` to ensure that it contains the data that you think it does. – Carcigenicate Mar 29 '21 at 00:30
  • What do you see if you uncomment the `print(response)` line? Seems important. – Samwise Mar 29 '21 at 00:30
  • I get everything .. running in cgi-bin, I get the same error. Seems like the call subprocess.Popen is not returning anything. But it does work ... .just not when I do it on apache/cgi-bin. The print (response) was a test to see what was being brought back ... – Greg Mar 29 '21 at 00:52

0 Answers0