tkrajina / gpxpy

gpx-py is a python GPX parser. GPX (GPS eXchange Format) is an XML based file format for GPS tracks.
Apache License 2.0
1.01k stars 223 forks source link

ParseError while posting file with request #204

Closed kiranlm closed 4 years ago

kiranlm commented 4 years ago

I have tried to read file from request instead of physical path

gpxFile = request.files['gpx'].read()
gpx = gpxpy.parse(gpxFile)

This one give me some error like:

File "C:\Users\kiran\anaconda3\envs\runcoach\lib\xml\etree\ElementTree.py", line 1315, in XML
    parser.feed(text)
  File "<string>", line None
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 1

Below one is working fine when I tried reading from local file:

gpx_file = open('data/tcs.gpx', 'r')
gpx = gpxpy.parse(gpx_file)

How can I parse the file from request

I'm posting as FormData like this: image

tkrajina commented 4 years ago

gpxpy.parse(gpxFile) accepts a file-like object or a string. In this case it probably isn't a valid file-like object or it's not a string. Log the type and contents of gpxFile to see what's in there.

Anyway, I'm closing this since this isn't an "issue" (it's a question - stackoverflow is a better places for asking questions).