Skip to main content
 首页 » 编程设计

python之如何跟踪与gpsd python库连接的GPS设备的ConnectionRefusedError原因

2025年01月19日32www_RR

我会简短地介绍一下:我有一个u-blox M8 GNSS评估套件,并且我试图在一个较大的程序中从中提取位置数据作为子例程。但是我一开始就很沮丧。我的程序在尝试建立初始连接时终止,出现以下错误:

ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it 


我以为也许其他进程正在监听gpsd的默认端口(2947),但是在调用“ netstat -a -n”(在Windows命令提示符下)后,我能够确认没有其他进程在阻塞该端口。我不知道如何进一步找出原因,并且急切希望有经验的用户提出任何建议。

编辑为懒惰添加更多上下文
该程序在connect调用期间中断(实际上是我自己程序的第一行),您可以在下面查看上下文:

def connect(host="127.0.0.1", port=2947): 
""" Connect to a GPSD instance 
:param host: hostname for the GPSD server 
:param port: port for the GPSD server 
""" 
global gpsd_socket, gpsd_stream, verbose_output, state 
logger.debug("Connecting to gpsd socket at {}:{}".format(host, port)) 
gpsd_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
gpsd_socket.connect((host, port)) 
gpsd_stream = gpsd_socket.makefile(mode="rw") 
logger.debug("Waiting for welcome message") 
welcome_raw = gpsd_stream.readline() 
welcome = json.loads(welcome_raw) 
if welcome['class'] != "VERSION": 
    raise Exception( 
        "Unexpected data received as welcome. Is the server a gpsd 3 server?") 
logger.debug("Enabling gps") 
gpsd_stream.write('?WATCH={"enable":true}\n') 
gpsd_stream.flush() 
 
for i in range(0, 2): 
    raw = gpsd_stream.readline() 
    parsed = json.loads(raw) 
    _parse_state_packet(parsed) 

请您参考如下方法:

由于Windows 10上不支持gpsd,因此您很愚蠢。 :(