gacou54 / pyorthanc

Python library that wrap the Orthanc REST API and facilitate the manipulation of data in Orthanc
MIT License
49 stars 10 forks source link

Raw_response option #38

Closed ylemarechal closed 1 year ago

ylemarechal commented 1 year ago

This code is working :

if __name__ == '__main__':
    client = pyorthanc.Orthanc('orthanc', timeout=200, return_raw_response=False)
    series = pyorthanc.find_series(client, {'Modality': 'SR'})

But this one is KO :

if __name__ == '__main__':
    client = pyorthanc.Orthanc('orthanc', timeout=200, return_raw_response=True)
    series = pyorthanc.find_series(client, {'Modality': 'SR'})

We get this error

TypeError: object of type 'Response' has no len()

from this line.

When raw_reponse option is enabled, methods using requests are ko when they are waiting for response.content and get response body instead.

A possibility would be to keep raw_response in inner methods and return content (according to return_raw_response option) in higher levels. @gacou54, what do you think ?

gacou54 commented 1 year ago

That's a very good point. Ideally, I would like the various utility functions to return the raw response, but this is unfortunately not possible in many cases. For example, find_series() accumulates results via several calls to Orthanc, which means that we would have several responses to collect (which is not very elegant).

For the moment, I suggest checking if it is a return_raw_response, and if it is True, we make a copy of the client with return_raw_response=False. What do you think @ylemarechal ?

ylemarechal commented 1 year ago

It is a good option. Thank you

gacou54 commented 1 year ago

Fixed in #42

Bugfix has been released in PyOrthanc v1.12.3