Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31950 > unrolled thread

PIL and requests don't get along

Started byroy@panix.com (Roy Smith)
First post2012-10-23 14:06 -0400
Last post2012-10-24 09:35 -0400
Articles 4 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  PIL and requests don't get along roy@panix.com (Roy Smith) - 2012-10-23 14:06 -0400
    Re: PIL and requests don't get along Alex Clark <aclark@aclark.net> - 2012-10-23 14:28 -0400
    Re: PIL and requests don't get along Kushal Kumaran <kushal.kumaran+python@gmail.com> - 2012-10-24 11:25 +0530
      Re: PIL and requests don't get along Roy Smith <roy@panix.com> - 2012-10-24 09:35 -0400

#31950 — PIL and requests don't get along

Fromroy@panix.com (Roy Smith)
Date2012-10-23 14:06 -0400
SubjectPIL and requests don't get along
Message-ID<k66mc3$ed3$1@panix2.panix.com>
I have a url from which I can get an image.  I want to use PIL to
manipulate that image.  Getting the image is easy:

>>> import requests
>>> r = requests.get(url)

There's a bunch of factory functions for Image, but none of them seem
to take anything that requests is willing to give you.  Image.new()
requires that you pass it the image size.  Image.open() takes a file
object, but

>>> Image.open(r.raw)

doesn't work because r.raw gives you a socket which doesn't support
seek().  I end up doing:

>>> r = requests.get(url)
>>> data = cStringIO.StringIO(r.content)
>>> image = Image.open(data)

which works, but it's gross.  Is there something I'm missing here?

[toc] | [next] | [standalone]


#31951

FromAlex Clark <aclark@aclark.net>
Date2012-10-23 14:28 -0400
Message-ID<mailman.2682.1351016950.27098.python-list@python.org>
In reply to#31950
On 2012-10-23 18:06:59 +0000, Roy Smith said:

> I have a url from which I can get an image.  I want to use PIL to
> manipulate that image.  Getting the image is easy:
> 
>>>> import requests
>>>> r = requests.get(url)
> 
> There's a bunch of factory functions for Image, but none of them seem
> to take anything that requests is willing to give you.  Image.new()
> requires that you pass it the image size.  Image.open() takes a file
> object, but
> 
>>>> Image.open(r.raw)
> 
> doesn't work because r.raw gives you a socket which doesn't support
> seek().  I end up doing:
> 
>>>> r = requests.get(url)
>>>> data = cStringIO.StringIO(r.content)
>>>> image = Image.open(data)
> 
> which works, but it's gross.  Is there something I'm missing here?


No idea but you can open a ticket here if you think it's appropriate:  
https://github.com/python-imaging/Pillow/issues


-- 
Alex Clark ยท https://www.gittip.com/aclark4life/

[toc] | [prev] | [next] | [standalone]


#32002

FromKushal Kumaran <kushal.kumaran+python@gmail.com>
Date2012-10-24 11:25 +0530
Message-ID<mailman.2725.1351058163.27098.python-list@python.org>
In reply to#31950
On 23 Oct 2012 14:06:59 -0400, roy@panix.com (Roy Smith) wrote:
> I have a url from which I can get an image.  I want to use PIL to
> manipulate that image.  Getting the image is easy:
> 
> >>> import requests
> >>> r = requests.get(url)
> 
> There's a bunch of factory functions for Image, but none of them seem
> to take anything that requests is willing to give you.  Image.new()
> requires that you pass it the image size.  Image.open() takes a file
> object, but
> 
> >>> Image.open(r.raw)
> 
> doesn't work because r.raw gives you a socket which doesn't support
> seek().  I end up doing:
> 
> >>> r = requests.get(url)
> >>> data = cStringIO.StringIO(r.content)
> >>> image = Image.open(data)
> 
> which works, but it's gross.  Is there something I'm missing here?

That is pretty much what the requests module documentation says here:

http://docs.python-requests.org/en/latest/user/quickstart/#binary-response-content

-- 
regards,
kushal

[toc] | [prev] | [next] | [standalone]


#32039

FromRoy Smith <roy@panix.com>
Date2012-10-24 09:35 -0400
Message-ID<roy-E1A4A4.09355524102012@news.panix.com>
In reply to#32002
In article <mailman.2725.1351058163.27098.python-list@python.org>,
 Kushal Kumaran <kushal.kumaran+python@gmail.com> wrote:

> On 23 Oct 2012 14:06:59 -0400, roy@panix.com (Roy Smith) wrote:
> > I have a url from which I can get an image.  I want to use PIL to
> > manipulate that image.  Getting the image is easy:
> > 
> > >>> import requests
> > >>> r = requests.get(url)
> > 
> > There's a bunch of factory functions for Image, but none of them seem
> > to take anything that requests is willing to give you.  Image.new()
> > requires that you pass it the image size.  Image.open() takes a file
> > object, but
> > 
> > >>> Image.open(r.raw)
> > 
> > doesn't work because r.raw gives you a socket which doesn't support
> > seek().  I end up doing:
> > 
> > >>> r = requests.get(url)
> > >>> data = cStringIO.StringIO(r.content)
> > >>> image = Image.open(data)
> > 
> > which works, but it's gross.  Is there something I'm missing here?
> 
> That is pretty much what the requests module documentation says here:
> 
> http://docs.python-requests.org/en/latest/user/quickstart/#binary-response-con
> tent

Heh, I hadn't even noticed that.  I guess this is as good as it gets.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web