python - Python 使用 gps 和 gps3 库的问题
问题描述
我正在尝试使用 python (3.8.2) 中的 GPS 库获取 gps 数据,但一直抛出相同的错误,即
[WinError 10061] 由于目标机器主动拒绝,无法建立连接
还尝试了 gps3 库并不断收到相同的错误。这是我的代码:
import threading
import time
from gps import *
class GpsPoller(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.session = gps(mode=WATCH_ENABLE)
self.current_value = None
def get_current_value(self):
return self.current_value
def run(self):
try:
while True:
self.current_value = self.session.next()
time.sleep(0.2)
except StopIteration:
pass
if __name__ == '__main__':
gpsp = GpsPoller()
gpsp.start()
while 1:
time.sleep(5)
print(gpsp.get_current_value())
这是错误的回溯,以防万一
Traceback (most recent call last):
File "test_gps_poller.py", line 27, in <module>
gpsp = GpsPoller()
File "test_gps_poller.py", line 11, in __init__
self.session = gps(mode=WATCH_ENABLE)
File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\gps\gps.py", line 197, in __init__
gpscommon.__init__(self, host, port, verbose, reconnect)
File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\gps\client.py", line 43, in __init__
self.connect(self.host, self.port)
File "C:\Users\user\AppData\Roaming\Python\Python37\site-packages\gps\client.py", line 69, in connect
self.sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
任何帮助将不胜感激,谢谢!
解决方案
推荐阅读
- python - 基于 np.array 的移动切片重建 np.array 的有效方法
- node.js - ejs变量增量不起作用
- c - 动态内存分配中的指针名称问题
- javascript - JQuery选中一个复选框,然后取消选中/禁用具有相同名称属性的其他人
- c# - Xamarin Android 在同一个文本视图中使用多种字体
- kotlin - Kotlin - How does Boolean? in if expression works on bytecode
- java - java.io.EOFException 引发的错误异常
- python - How do I make Python code to execute only once?
- xcode - 在 Xcode 中禁用#imageLiteral(resourceName: <..>) 预览?
- c# - AspNet Core 中 UTC 的 Http 查询参数