上传 .gpx 文件 Streamlit Python

问题描述

我使用 python 制作了一个 Streamlit 应用程序,可以在其中拖放 gpx 文件

import streamlit as st 
file = st.file_uploader("Upload a strava file (gpx)",type=["gpx"],accept_multiple_files=False)

enter image description here

但是,无法使用包 gpxpy 包打开 InMemoryUploadedFile。给我一个 KeyError: 3655

import gpxpy
gpx = gpxpy.parse(file)

有人可以帮我吗?

解决方法

请尝试:

import streamlit as st
import gpxpy

file = st.file_uploader("Upload a strava file (gpx)",type=["gpx"],accept_multiple_files=False)

if uploaded_file is not None:
    gpx = gpxpy.parse(uploaded_file)

还请确保 streamlit 和 gpxpy 都更新到最新版本并且 gpx 文件没有损坏