How to download thumbnail (or other non-JSON-encoded) using python REST API?
See original GitHub issuePardon my ignorance, my knowledge of server requests is quite limited. I am trying to get the thumbnail and tiles of a slide from HTK to my python interpreter so I can do some analysis. I am getthing this error because it is not JSON-encoded and girder_client assumes JSON (if my understanding is correct). I would appreciate any help with this. Thanks!
Code I am using:
import requests
import json
import girder_client
# Connect to API
apiUrl = 'http://candygram.neurology.emory.edu:8080/api/v1/'
gc= girder_client.GirderClient(apiUrl = apiUrl)
gc.authenticate(interactive=True)
thumbnail = gc.get("item/%s/tiles/thumbnail" % slide_id)
Error message
JSONDecodeError Traceback (most recent call last)
<ipython-input-60-acc36e14b24f> in <module>()
----> 1 gc.get("item/%s/tiles/thumbnail" % slide_id)
~/.conda/envs/wsi/lib/python3.5/site-packages/girder_client/__init__.py in get(self, path, parameters, jsonResp)
501 Convenience method to call :py:func:`sendRestRequest` with the 'GET' HTTP method.
502 """
--> 503 return self.sendRestRequest('GET', path, parameters, jsonResp=jsonResp)
504
505 def post(self, path, parameters=None, files=None, data=None, json=None, headers=None,
~/.conda/envs/wsi/lib/python3.5/site-packages/girder_client/__init__.py in sendRestRequest(self, method, path, parameters, data, files, json, headers, jsonResp, **kwargs)
489 if result.status_code in (200, 201):
490 if jsonResp:
--> 491 return result.json()
492 else:
493 return result
~/.conda/envs/wsi/lib/python3.5/site-packages/requests/models.py in json(self, **kwargs)
894 # used.
895 pass
--> 896 return complexjson.loads(self.text, **kwargs)
897
898 @property
~/.conda/envs/wsi/lib/python3.5/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
317 parse_int is None and parse_float is None and
318 parse_constant is None and object_pairs_hook is None and not kw):
--> 319 return _default_decoder.decode(s)
320 if cls is None:
321 cls = JSONDecoder
~/.conda/envs/wsi/lib/python3.5/json/decoder.py in decode(self, s, _w)
337
338 """
--> 339 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
340 end = _w(s, end).end()
341 if end != len(s):
~/.conda/envs/wsi/lib/python3.5/json/decoder.py in raw_decode(self, s, idx)
355 obj, end = self.scan_once(s, idx)
356 except StopIteration as err:
--> 357 raise JSONDecodeError("Expecting value", s, err.value) from None
358 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Get raw thumbnail using rest api - Pipeline Integrations
I'm trying to display the full res thumbnail inside of another webpage I've created. So i need a direct path to the image....
Read more >Trying to add item (jpg image) with thumbnail usin...
Hi! I am adding multiple images (jpg format) to ArcGIS Portal using Python REST API. So far the part of the code that...
Read more >How to generate thumbnail for attachment uploaded via the ...
I am creating a tool for our own confluence server using python ... I am using atlassian-rest-api to upload documents and update the...
Read more >How to Download a YouTube Video Thumbnail with NO ...
By APIs with Valentine. Learn APIs. Become a better tester. Get tips and tutorials right in your inbox. No more than 1-2 emails...
Read more >REST API - Tableau and Behold!
One of the conditions that results in a gray generic thumbnails is any workbook that is connected to a Published Data Source that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Mohamed we have multiple python notebooks showing how to do this… chat with me or JC tomorrow and we will point you in the right direction…
On Sat, Aug 25, 2018 at 8:05 PM Mohamed Amgad Tageldin < notifications@github.com> wrote:
– David A Gutman MD PhD Assistant Professor of Neurology, Psychiatry & Biomedical Informatics Emory University School of Medicine Staff Physician, Mental Health Service Line Atlanta VA Medical Center
The response from that endpoint is
image/jpeg
notapplication/json
. To use girder client to read it, try:To get a numpy array, you will need to decode it. Using PIL you can do something like this