Failed to read project permissions using Python API

Solved!
Turribeach
Failed to read project permissions using Python API

Hi, I am trying to read project metada using the Python API from outside DSS. This is my code snippet:

 

 

 

 

 

import dataikuapi
host = "https://our_dss_instance"
apiKey = "my API key"
client = dataikuapi.DSSClient(host, apiKey)
client._session.verify = False
project = client.get_project("my project key")
project.get_metadata()

 

 

 

 

 

The above fails with the following error:

 

 

 

 

 

/data/anaconda/lib/python3.6/site-packages/urllib3/connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
/data/anaconda/lib/python3.6/site-packages/dataikuapi/dssclient.py in _perform_http(self, method, path, params, body, stream, files, raw_body)
    995                     stream = stream)
--> 996             http_res.raise_for_status()
    997             return http_res

/data/anaconda/lib/python3.6/site-packages/requests/models.py in raise_for_status(self)
    939         if http_error_msg:
--> 940             raise HTTPError(http_error_msg, response=self)
    941 

HTTPError: 403 Client Error: Forbidden for url: https://dss_url/dip/publicapi/projects/project_name/metadata

During handling of the above exception, another exception occurred:

DataikuException                          Traceback (most recent call last)
<ipython-input-4-63c4e3d41a73> in <module>()
----> 1 project.get_metadata()

/data/anaconda/lib/python3.6/site-packages/dataikuapi/dss/project.py in get_metadata(self)
    200         :rtype: dict
    201         """
--> 202         return self.client._perform_json("GET", "/projects/%s/metadata" % self.project_key)
    203 
    204     def set_metadata(self, metadata):

/data/anaconda/lib/python3.6/site-packages/dataikuapi/dssclient.py in _perform_json(self, method, path, params, body, files, raw_body)
   1010 
   1011     def _perform_json(self, method, path, params=None, body=None,files=None, raw_body=None):
-> 1012         return self._perform_http(method, path,  params=params, body=body, files=files, stream=False, raw_body=raw_body).json()
   1013 
   1014     def _perform_raw(self, method, path, params=None, body=None,files=None, raw_body=None):

/data/anaconda/lib/python3.6/site-packages/dataikuapi/dssclient.py in _perform_http(self, method, path, params, body, stream, files, raw_body)
   1001             except ValueError:
   1002                 ex = {"message": http_res.text}
-> 1003             raise DataikuException("%s: %s" % (ex.get("errorType", "Unknown error"), ex.get("message", "No message")))
   1004 
   1005     def _perform_empty(self, method, path, params=None, body=None, files = None, raw_body=None):

DataikuException: com.dataiku.dip.exceptions.UnauthorizedException: Failed to read project permissions

 

 

 I tried with a user API key (which owns the project) and a project API key. Same error. I even tried with a global administrator API and got the same error. Any ideas?

1 Solution
Turribeach
Author
OK I looked at the backend log and found the problem. The error is misleading, there is a second error not shown on the API call error:
 
Caused by: com.dataiku.dip.server.controllers.NotFoundException: Project does not exist: MyProject
 
This is due to the project key being case sensitive so I should have used MYPROJECT rather than MyProject. Still it's not very helping that you don't see the actual error in the API call. 

View solution in original post

1 Reply
Turribeach
Author
OK I looked at the backend log and found the problem. The error is misleading, there is a second error not shown on the API call error:
 
Caused by: com.dataiku.dip.server.controllers.NotFoundException: Project does not exist: MyProject
 
This is due to the project key being case sensitive so I should have used MYPROJECT rather than MyProject. Still it's not very helping that you don't see the actual error in the API call.