We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
环境:windows10; python=3.11; gpxpy=1.3.1 问题:读取Garmin connect网页下载的gpx类型文件运行,提示
gpxpy.gpx.GPXXMLSyntaxException: Error parsing XML: not well-formed (invalid token): line 1, column 1
似乎将main.py文件第26行rb修改为r即可正确运行(不知道原代码为何用rb),其他使用Garmin设备的朋友可以参考一下 btw非常感谢作者的贡献!
The text was updated successfully, but these errors were encountered:
感谢提出这个问题,之所以这样写,使因为我对 gpxpy 的 GPXParser 类有误解。GPXParser 的 init 方法可接受的类型为 Union[AnyStr, IO[str]],我认为其可以处理不同编码格式的文件,但刚刚看了 gpxpy 的源码后才发现其对 bytes 类型的处理为 string.decode(),这个 build-in 方法默认会按 uft-8 解码字符串。也就是说,截止目前,这个 Python 工具只支持 utf-8 的文件。
Union[AnyStr, IO[str]]
bytes
string.decode()
我猜测您的文件可能是 GBK 或其他格式编码,也希望您可以帮忙确认这一点。python build-in 方法 open 的默认解码方式和操作系统相关,在 Windows 上为 ANSI code page。如果系统为中文,文件编码为 GBK 或 GB2312,将 rb 改为 rt 可以解决这个问题。
open
rb
rt
但是代码中还不能直接将 rb 改为 rt,这会破坏 Windows 环境下对 utf-8 文件的支持,当前建议使用两个方案:
后面我会尝试修改代码以支持不同操作系统下不同编码,也欢迎PR
Sorry, something went wrong.
感谢您的详尽回复!似乎我的输入文件是UTF-8编码,附在这里 test.zip
No branches or pull requests
环境:windows10; python=3.11; gpxpy=1.3.1
问题:读取Garmin connect网页下载的gpx类型文件运行,提示
似乎将main.py文件第26行rb修改为r即可正确运行(不知道原代码为何用rb),其他使用Garmin设备的朋友可以参考一下
btw非常感谢作者的贡献!
The text was updated successfully, but these errors were encountered: