question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Downloaded xml's have unexpected tokens at top.

See original GitHub issue

My actions before raising this issue

  • Read/searched the docs
  • Searched past issues

Annotations have unexpected tokens at top when downloaded via api in CVAT XML 1.1 for videos format. Downloading from UI has no issues.

Expected Behaviour

Downloaded annotations should not contain unexpected tokens.

Current Behaviour

Downloaded annotations have unexpected tokens at the top of the xml file.

Possible Solution

Steps to Reproduce (for bugs)

  1. Download a tasks annotations via rest api.

Context

Downloading a batch of annotations is practical via api, and useful in automating the process.

Your Environment

  • CVAT alpha build 1.1.0
  • OS : Centos 8

Next steps

You may join our Gitter channel for community support.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
Boazrciasncommented, Oct 19, 2020

Hello Katarina, I have found out that downloaded files are zip files. You can save it then unzip the file and save again. It is not the best solution though but you can use the following code if you like to directly dump to xml. You need the zipfile package. You should change the same named function of CLI class.


    def tasks_dump(self, task_id, fileformat, filename, **kwargs):
        """ Download annotations for a task in the specified format
        (e.g. 'YOLO ZIP 1.0')."""
        url = self.api.tasks_id(task_id)
        response = self.session.get(url)
        response.raise_for_status()
        response_json = response.json()

        url = self.api.tasks_id_annotations_filename(task_id,
                                                     response_json['name'],
                                                     fileformat)
        while True:
            response = self.session.get(url)
            response.raise_for_status()
            if response.status_code == 201:
                break

        response = self.session.get(url + '&action=download')
        response.raise_for_status()
        fbytes = BytesIO(response.content)
        zipf = ZipFile(fbytes)
        with codecs.open(filename, 'wb') as fp:
            fp.write(zipf.read('annotations.xml'))

Best Barış

1reaction
Boazrciasncommented, Aug 11, 2020

response header content type appears as ‘application/zip’ , shouldn’t it be something different? I cannot encode the byte array to utf-8

UPDATE: Apparently this is because response is a zip file, everything is fine when I contents as a zip file. But in CLI page the example is with an xml file which was the case in previous ones. Check, https://github.com/opencv/cvat/blob/develop/utils/cli/README.md

From CLI, I would prefer unzipped versions or an option to choose if possible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected token <> in expression or statement - TechNet
I'm tryingt o edit the contents of a xml file and switch a value from true to false. <?xml version="1.0"?> <Categories xmlns="link">
Read more >
c# - Download .xls file using Angular: Unexpected token P in ...
I have the following server method for returning an byte[] for an xls document stored in Azure Blob Storage .
Read more >
Xml parser unexpected token error position:TEXT @1:2 in java ...
The problem is when I parse the XML from the original link for example (i am not posting the original link due to...
Read more >
Unexpected Token Error when trying to add Index file - Reddit
Copy that address, paste it into additional content, try and download and get the error.
Read more >
Unexpected token [$] in path expression - Oxygen XML Forum
Hi, I'm merging 2 XML files and get in some trouble. How can I do the following ? <!-- path to second XML:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found