Hello Hari,

Have you tried with a content_type of 'image/*'?

Best,
Alain

On Fri, Sep 16, 2011 at 5:41 AM, Hari <[email protected]> wrote:

> Hi Vinay,
>
> First, my sincere apologies for not getting back, I got swamped with other
> things and couldn't find time to give your suggestions a try. I finally
> changed my code to use version 3 API and got most of the functionality back
> (except for the group assignment, but I haven't debugged it yet). I am now
> back to the same issue with the ChangePhoto(). I tried different variations
> and all fail, though with different errors. When I try downloading the image
> and explicitly create the MediaSource like this:
>
>     photosrc = urllib2.urlopen(photo_url)
>     photodata = photosrc.read()
>     gd_client.ChangePhoto(gdata.data.MediaSource(StringIO(photodata),
>                                                  content_type=
> photosrc.info().typeheader,
>
> content_length=len(photodata)),
>                           contact_entry_or_url)
>
> I get the error that I previously reported, so I tried changing the
> content_type to "image/png", and still get the same error, though it now
> refers to "image/png" instead of "image/jpeg". Here is the traceback:
>
>
> Traceback (most recent call last):
>   File "scrape_contact.py", line 181, in <module>
>     main()
>   File "scrape_contact.py", line 178, in main
>
>     change_photo(options, None, options.contacturl, options.photo_url)
>   File "scrape_contact.py", line 141, in change_photo
>     contact_entry_or_url)
>   File
> "/Users/hdara/bin/python/lib/python2.6/site-packages/gdata/contacts/client.py",
> line 288, in change_photo
>     ifmatch_header=ifmatch_header, **kwargs)
>   File
> "/Users/hdara/bin/python/lib/python2.6/site-packages/atom/client.py", line
> 142, in put
>     http_request=http_request, data=data, **kwargs)
>   File
> "/Users/hdara/bin/python/lib/python2.6/site-packages/gdata/client.py", line
> 319, in request
>     RequestError)
> gdata.client.RequestError: Server responded with: 415, Content-Type
> image/png is not a valid input type.
>
> I even tried passing in a file('/path/to/image') and that too generates the
> same error as above, and this definitely worked before. If I pass the url
> stream directly, like this:
>
>     gd_client.ChangePhoto(urllib2.urlopen(photo_url),
>                           contact_entry_or_url,
>                           content_type='image/jpeg')
>
> I get this error:
>
>
> Traceback (most recent call last):
>   File "scrape_contact.py", line 181, in <module>
>     main()
>   File "scrape_contact.py", line 178, in main
>
>     change_photo(options, None, options.contacturl, options.photo_url)
>   File "scrape_contact.py", line 152, in change_photo
>     content_type='image/jpeg')
>   File
> "/Users/hdara/bin/python/lib/python2.6/site-packages/gdata/contacts/client.py",
> line 288, in change_photo
>     ifmatch_header=ifmatch_header, **kwargs)
>   File
> "/Users/hdara/bin/python/lib/python2.6/site-packages/atom/client.py", line
> 142, in put
>     http_request=http_request, data=data, **kwargs)
>   File
> "/Users/hdara/bin/python/lib/python2.6/site-packages/gdata/client.py", line
> 267, in request
>     uri=uri, auth_token=auth_token, http_request=http_request, **kwargs)
>   File
> "/Users/hdara/bin/python/lib/python2.6/site-packages/atom/client.py", line
> 98, in request
>     value.modify_request(http_request)
>   File "/Users/hdara/bin/python/lib/python2.6/site-packages/gdata/data.py",
> line 1216, in modify_request
>     self.content_length)
>   File
> "/Users/hdara/bin/python/lib/python2.6/site-packages/atom/http_core.py",
> line 122, in add_body_part
>     raise UnknownSize('Each part of the body must have a known size.')
> atom.http_core.UnknownSize: Each part of the body must have a known size.
>
> Do you happen to get this functionality working? Could you share a snippet?
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Google Contacts, Shared Contacts and User Profiles APIs" group.
> To post to this group, send email to
> [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://code.google.com/apis/contacts/community/forum.html
>



-- 
Alain Vongsouvanh | Developer Programs Engineer

-- 
You received this message because you are subscribed to the Google
Groups "Google Contacts, Shared Contacts and User Profiles APIs" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://code.google.com/apis/contacts/community/forum.html

Reply via email to