access to ArcGIS Notebook file system - getting error from arcgis.gis.nb.NotebookServer.data_access.files

705
0
05-09-2022 03:20 PM
davedoesgis
Occasional Contributor III

I'm trying to access the files from my ArcGIS Notebook. I thought it would be helpful to develop in an IDE on my local system and write a little script to deploy all the file dependencies into /arcgis/home. 

I can connect to the GIS() via a saved profile, get the Item for my Notebook, get the list of tasks, etc., but I'm stuck on accessing the files. My understanding is that I'm supposed to create a NotebookServer object (arcgis.gis.nb.NotebookServer) and its data_access property returns an arcgis.gis.nb._dataaccess.NotebookDataAccess object. That has a files property and an upload() method which should be the rest of what I need.

Here's what I'm trying: 

base_agol_url = 'https://<MY_ORG>.maps.arcgis.com'
gis = GIS(profile='AGOL')
nb_server = NotebookServer(url=base_agol_url, gis=gis)
nb_da = nb_server.data_access
nb_da.files  # THIS LINE FAILS

After line 4, I have the nb_da variable, which is a NotebookDataAccess object and it has all the properties I'd expect. Line 5, however, returns a json.decoder.JSONDecodeError with a super lengthy Traceback (see below). To instantiate NotebookServer (line 3), you pass in a URL and a gis object. I assume the URL is the base URL for our AGOL instance, but the gis object has that URL embedded, so that seems redundant. I tried guessing at a few other URLs on line 3, including https://notebooksservices.arcgis.com/adminbut didn't make any progress. 

Does anyone have some sample code to create a NotebookDataAccess object with a valid set of files? I think once I get that going, I'll be off to the races. 

Here is the traceback from line 5 in the code snippet above: 

Traceback (most recent call last):
  File "C:\Users\<USER>\AppData\Local\ESRI\conda\envs\conda_env\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 610, in _handle_response
    data = resp.json()
  File "C:\Users\<USER>\AppData\Local\ESRI\conda\envs\conda_env\lib\site-packages\requests\models.py", line 900, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Users\<USER>\AppData\Local\ESRI\conda\envs\conda_env\lib\json\__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "C:\Users\<USER>\AppData\Local\ESRI\conda\envs\conda_env\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\<USER>\AppData\Local\ESRI\conda\envs\conda_env\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\eclipse\plugins\org.python.pydev.core_7.6.0.202006041357\pysrc\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<console>", line 1, in <module>
  File "C:\Users\<USER>\AppData\Local\ESRI\conda\envs\conda_env\lib\site-packages\arcgis\gis\nb\_dataaccess.py", line 102, in files
    for f in self._gis._con.get(url, params).pop("Blobs", [])
  File "C:\Users\<USER>\AppData\Local\ESRI\conda\envs\conda_env\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 506, in get
    ignore_error_key=ignore_error_key,
  File "C:\Users\<USER>\AppData\Local\ESRI\conda\envs\conda_env\lib\site-packages\arcgis\gis\_impl\_con\_connection.py", line 613, in _handle_response
    raise Exception(resp.text)
Exception: <!DOCTYPE html> 
<html> 
<head> 
  <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
  <link rel="stylesheet" href="https://cdn-a.arcgis.com/cdn/1A3502F/js/calcite-web/dist/css/calcite-web-no-fonts.min.css"> 
  <link rel="stylesheet" href="https://cdn-a.arcgis.com/cdn/1A3502F/js/arcgisonline/css/app.css"> 
</head> 
<body> 
  <div class="loader is-active padding-leader-5 padding-trailer-5 js-page-loader"> 
    <div class="loader-bars"></div> 
    <div class="loader-text"></div> 
  </div> 
  <script type="text/javascript" src="/home/js/arcgisonline/config.js"></script> 
  <script src="https://cdn-a.arcgis.com/cdn/1A3502F/js/jsapi/dojo/dojo.js"></script> 
  <script> 
    esriGeowConfig.pageNotFound = true; 
    require(window.dojoConfig, ["arcgisonline/main"]); 
  </script> 
</body> 
</html>

 

@RaviNarayanan , @MobiusSnake - tag, you guys might know the answer!

0 Kudos
0 Replies