ndexbio / ndex2-client

NDEx2 Client
BSD 3-Clause "New" or "Revised" License
6 stars 6 forks source link

set_network_properties -> 500 Server Error #77

Closed ariutta closed 3 years ago

ariutta commented 3 years ago

The set_network_properties method is giving me an unexpected error:

HTTPError: 500 Server Error: 500 for url: http://test.ndexbio.org/v2/network/07ce188f-dd0a-11ea-9101-0660b7976219/properties

I am using version 3.3.1 of this library.

I can successfully run other methods like set_network_system_properties and set_read_only. In fact, if I comment out the set_network_properties line in the code below, it runs OK. But with that line enabled, I get the error.

Code

ndex_user = os.environ["NDEX_USER"]
ndex_pwd = os.environ["NDEX_PWD"]
ndex_url = "http://test.ndexbio.org"
my_ndex = ndex2.client.Ndex2(
    ndex_url, ndex_user, ndex_pwd, update_status=True, debug=True, user_agent="pfocr"
)

network_id = "07ce188f-dd0a-11ea-9101-0660b7976219"
network_summary = my_ndex.get_network_summary(network_id)

my_ndex.set_read_only(network_id, False)
my_ndex.set_network_system_properties(network_id, {"readOnly": False})
my_ndex.set_network_properties(network_id, [{"dummyProperty": "dummy value"}])
my_ndex.set_read_only(network_id, True)
my_ndex.set_network_system_properties(network_id, {"readOnly": True})

Error

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-93-5f64b9f67188> in <module>
     11 my_ndex.set_read_only(network_id, False)
     12 my_ndex.set_network_system_properties(network_id, {"readOnly": False})
---> 13 my_ndex.set_network_properties(network_id, [{"dummyProperty": "dummy value"}])
     14 my_ndex.set_read_only(network_id, True)
     15 my_ndex.set_network_system_properties(network_id, {"readOnly": True})

/nix/store/ifnk3pq2jywslprlzsn046sfzm942ywm-python3-3.7.5-env/lib/python3.7/site-packages/ndex2/client.py in set_network_properties(self, network_id, network_properties)
    835             raise Exception("network_properties must be a string or a list "
    836                             "of NdexPropertyValuePair objects")
--> 837         return self.put(route, put_json)
    838 
    839     def get_sample_network(self, network_id):

/nix/store/ifnk3pq2jywslprlzsn046sfzm942ywm-python3-3.7.5-env/lib/python3.7/site-packages/ndex2/client.py in put(self, route, put_json)
    227             response = self.s.put(url, headers=headers,
    228                                   timeout=self.timeout)
--> 229         return self._return_response(response)
    230 
    231     def post(self, route, post_json):

/nix/store/ifnk3pq2jywslprlzsn046sfzm942ywm-python3-3.7.5-env/lib/python3.7/site-packages/ndex2/client.py in _return_response(self, response, raiseforstatus, returnfullresponse, returnjsonundertry)
    194         self.debug_response(response)
    195         if raiseforstatus:
--> 196             response.raise_for_status()
    197         if returnfullresponse is True:
    198             return response

/nix/store/iwqvxb95wf5bp05r46g9i462z0wcf6d0-python3.7-requests-2.22.0/lib/python3.7/site-packages/requests/models.py in raise_for_status(self)
    938 
    939         if http_error_msg:
--> 940             raise HTTPError(http_error_msg, response=self)
    941 
    942     def close(self):

HTTPError: 500 Server Error: 500 for url: http://test.ndexbio.org/v2/network/07ce188f-dd0a-11ea-9101-0660b7976219/properties
ariutta commented 3 years ago

Maybe related to #70?

coleslaw481 commented 3 years ago

So Ndex2.set_network_properties() in version 3.3.1 needs some TLC. The documentation is lacking big time.

First, the format of each property needs to be a dict:

{
  "subNetworkId": "",
  "predicateString": "",
  "dataType": "",
  "value": ""
}

Then the above dict must be put in a list.

Format for above is from: http://openapi.ndextools.org/#/Network/put_network__networkid__properties

The dataType must be one of the following: https://ndex2.readthedocs.io/en/latest/ndex2.html?highlight=list_of_string#supported-data-types

Here is an example on how to replace network properties on a network for version 3.3.1:

# network_id is NDEx UUID of network

foo = [{'subNetworkId': '', 
           'predicateString': 'dummyProperty', 
           'dataType': 'string', 
           'value': 'dummy value'
}]

my_ndex.set_network_properties(network_id, foo)

hope this helps,

chris

ariutta commented 3 years ago

Thanks, Chris. This appears to be working now.

coleslaw481 commented 3 years ago

Updated documentation in 3.3.2 release