Windows
Slicer 4.13
The script repository snippet “Download and install an extension”
throws a “Key error: ‘item_id’” exception when used in Slicer 4.13
Has anything changed ?
Thank you.
Windows
Slicer 4.13
The script repository snippet “Download and install an extension”
throws a “Key error: ‘item_id’” exception when used in Slicer 4.13
Has anything changed ?
Thank you.
Thanks for the report
Indeed, we updated the infrastructure and some the API details changed.
For reference, see Downloading extensions for older releases
Waiting we update the documentation and fix the legacy server to support this snippet, when using Slicer 4.13, you could do this:
extensionName = 'SlicerIGT'
em = slicer.app.extensionsManagerModel()
if not em.isExtensionInstalled(extensionName):
extensionMetaData = em.retrieveExtensionMetadataByName(extensionName)
- url = em.serverUrl().toString()+'/download/item/'+extensionMetaData['item_id']
- extensionPackageFilename = slicer.app.temporaryPath+'/'+extensionMetaData['_id']
+ url = em.serverUrl().toString() + '/download?items='+extensionMetaData['_id']
+ extensionPackageFilename = slicer.app.temporaryPath+'/'+extensionMetaData['_id']
slicer.util.downloadFile(url, extensionPackageFilename)
em.installExtension(extensionPackageFilename)
slicer.util.restart()
For convenience, here is the full snippet for easy copy-paste:
extensionName = 'SlicerIGT'
em = slicer.app.extensionsManagerModel()
if not em.isExtensionInstalled(extensionName):
extensionMetaData = em.retrieveExtensionMetadataByName(extensionName)
url = em.serverUrl().toString() + '/download?items='+extensionMetaData['_id']
extensionPackageFilename = slicer.app.temporaryPath+'/'+extensionMetaData['_id']
slicer.util.downloadFile(url, extensionPackageFilename)
em.installExtension(extensionPackageFilename)
slicer.util.restart()
Waiting we […] fix the legacy server
Issue is now tracked in
Waiting we update the documentation and fix the legacy server to support this snippet, when using Slicer 4.13, you could do this:
Thank you @jcfr .
I tested the new snippet in 4.13.0-2021-09-11 r30174 / 0db2e6e but got:
urllib.error.HTTPError: HTTP Error 404: Not Found
Failed to download file from https://slicer-packages.kitware.com/download?items=613dbbc4342a877cb3bf8bd4
Any ideas ?
I initially thought this was for the latest stable release, for the preview build, you could do that:
Replace em.serverUrl().toString()
with `“https://slicer.kitware.com/midas3/”’
This seems to work. Thank you
Unfortunately, it is not quite working yet.
If I use this code in 4.13:
extensionName = 'SlicerIGT'
em = slicer.app.extensionsManagerModel()
if not em.isExtensionInstalled(extensionName):
extensionMetaData = em.retrieveExtensionMetadataByName(extensionName)
url = "https://slicer.kitware.com/midas3" + '/download?items='+extensionMetaData['_id']
extensionPackageFilename = slicer.app.temporaryPath+'/'+extensionMetaData['_id']
slicer.util.downloadFile(url, extensionPackageFilename)
em.installExtension(extensionPackageFilename)
slicer.util.restart()
there is no error message or exception, but the extension that is installed seems not to be the right version:
If I install SlicerIGT from the extension manager I seem to get the correct version:
Obviously, this URL
https://slicer.kitware.com/midas3/download?items=613dbbc4342a877cb3bf8bd4
downloads SlicerIGT from the extension server which is no longer active in 4.13.
That is why the extension is older and shows outdated in 4.13.
But what would be the download URL to be used from 4.13 and to get the latest extension version?
To simplify things, here is a script that works without any changes in both Slicer-4.11 and Slicer-4.13:
extensionName = 'SlicerIGT'
em = slicer.app.extensionsManagerModel()
if not em.isExtensionInstalled(extensionName):
extensionMetaData = em.retrieveExtensionMetadataByName(extensionName)
if slicer.app.majorVersion*100+slicer.app.minorVersion < 413:
# Slicer-4.11
itemId = extensionMetaData['item_id']
url = f"{em.serverUrl().toString()}/download?items={itemId}"
else:
# Slicer-4.13
itemId = extensionMetaData['_id']
url = f"{em.serverUrl().toString()}/api/v1/item/{itemId}/download"
extensionPackageFilename = slicer.app.temporaryPath+'/'+itemId
slicer.util.downloadFile(url, extensionPackageFilename)
em.installExtension(extensionPackageFilename)
slicer.util.restart()
Thanks, but unfortunately this still loads an outdated version of the extension into 4.13:
Downloading from
https://slicer-packages.kitware.com/api/v1/item/613dbbc4342a877cb3bf8bd4/download
as file
C:/Users/Rudolf/AppData/Local/Temp/Slicer/613dbbc4342a877cb3bf8bd4
It may take a few minutes...
but result is:
30174 was some random nightly build some time ago. Please use latest Slicer Stable Release or latest Slicer Preview Release and let us know if you have problems with any of those.
@rbumm You’re likely not going to be able to stay on an older version of Slicer 4.13 from the early period of the extension manager transition where some fixes were still being worked out on the Slicer side. Including Unable to manually install extension with ExtensionsManager · Issue #5840 · Slicer/Slicer · GitHub.
Thank you.
The script now works with r30272 (preview) as well as the latest stable release.