1

I would like to read an image stored in google drive from an ipython notebook. I tried already using Image and requests as:

import requests
from ipywidgets import Image
img  = Image(requests.get("https://drive.google.com    /open?id=XXXX4"))
type(img)
img

but the image is broken. Or if I use the url input explicitly:

img  = Image(url=https://drive.google.com    /open?id=XXXX4")
type(img)
img

The '.com=....' is recognized as the format of the image so I got:

ValueError: Cannot embed the '.com=...' image format

Also I tried to directly import the file using requests library but in that case the whole html is returned which is not what I want... Any idea is appreciated.

ai2016
  • 2,721
  • 2
  • 11
  • 19
  • Why not use `Image` from `IPython.display`? – Georgy Feb 13 '18 at 16:27
  • same thing... broken image – ai2016 Feb 13 '18 at 16:30
  • This issue is only with Google Drive? Images from other websites are shown without any problems? – Georgy Feb 13 '18 at 16:41
  • Possible duplicate of [Displaying files (e.g. images) stored in Google Drive on a website](https://stackoverflow.com/questions/10311092/displaying-files-e-g-images-stored-in-google-drive-on-a-website) – Georgy Feb 13 '18 at 16:51
  • The problem is that using the Image function the extension is taken from the link. Now since the link doesn't contain the extension (jpg , png etc.) the function return the ValueError. Alternatively the requests method retrieve an html which is not the way to go – ai2016 Feb 13 '18 at 17:03
  • [Docs](http://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html?highlight=Image#IPython.display.Image) say that you can specify `format` of an image. – Georgy Feb 13 '18 at 17:11
  • Same goes for `ipywidgets`: [link](http://ipywidgets.readthedocs.io/en/stable/examples/Widget%20List.html?highlight=Image#Image), but it seems that you can't read images from url with it. – Georgy Feb 13 '18 at 17:14
  • ok I think google drive is changing the access of the url any time I open the file so the request library gets a forbidden message ... I guess I can't use google drive – ai2016 Feb 13 '18 at 17:37
  • Did you see the link I sent above? Alternative ways of hosting are described [here](https://gsuite-developers.googleblog.com/2016/07/reminder-turn-down-of-google-drive-web.html) – Georgy Feb 13 '18 at 17:41
  • yes I did and I did but if you see at the end the only way to make it work on drive it would be to save the image without the extension... don't like that I'm trying dropbox – ai2016 Feb 13 '18 at 17:46

0 Answers0