Home>

I'm trying to measure the downlink and uplink speeds for a fixed server with python, but I get an exception when down_result = stest.download ().

The behavior of speedtest is to ping and go down and up to the server with the least delay
I heard that the speed rule of is always done, and I always want to fix the connection destination
I thought that I set servers = [28910, 20976], but is this description wrong?

I would like to know how to fix the connection destination and execute the speed test on the two connection destinations.

# 28910 fdcservers.net
# 20976 GLBB Japan
import sys
import speedtest

def get_speed_test ():
    servers = [28910, 20976]
    stest = speedtest.Speedtest ()
    # stest.get_servers (servers) # I thought it was unnecessary because the connection destination was fixed
    # stest.get_best_server () # I thought it was unnecessary because the connection destination was fixed

def command_line_runner ():
    stest = get_speed_test ()
    down_result = stest.download () # An exception is thrown.
    up_result = stest.upload ()
    mbps_down_result = down_result/1024/1024
    mbps_up_result = up_result/1024/1024
    result = [mbps_down_result, mbps_up_result]
    print (result)
command_line_runner ()
  • Answer # 1

    stest.get_servers (servers)
    Without
    stest.get_servers ()
    If set to, the connection destination may not be fixed.

    To fix the connection destination
    stest.get_servers (servers)
    Must be.

    (Get_best_server () checks the ping of the server specified by get_servers and selects the earlier one as the connection destination.)

    The reason for the exception is that the def get_speed_test () function returns None. (Regardless of whether you specify servers)

    Try modifying it to return a SpeedTest object as shown below.

    def get_speed_test ():
        servers = [28910, 20976]
        stest = speedtest.Speedtest ()
        stest.get_servers (servers) #Specify the connection destination
        stest.get_best_server () # Check the ping of the specified connection destination and select the one with the smaller latency.
        return stest # Returns the set SpeedTest object.
    (Omitted below)