def _update_image(facebook_id, image_url):
 image_name = ('fb_image_%s.jpg' % facebook_id)
 image_temp = NamedTemporaryFile()
 try:
  image_response = urllib2.urlopen(image_url)
 except AttributeError:
  image_response = urllib.request.urlopen(image_url)
 image_content = image_response.read()
 image_temp.write(image_content)
 http_message = image_response.info()
 image_size = len(image_content)
 try:
  content_type = http_message.type
 except AttributeError:
  content_type = http_message.get_content_type()
 image_file = InMemoryUploadedFile(file=image_temp, name=image_name, field_name='image', content_type=content_type, size=image_size, charset=None)
 image_file.seek(0)
 image_temp.flush()
 return (image_name, image_file)

def _update_image ( facebook_id , image_url ) : image_name = ( 'fb_image_%s.jpg' % facebook_id ) image_temp = NamedTemporaryFile ( ) try : image_response = urllib2 . urlopen ( image_url ) except AttributeError : image_response = urllib . request . urlopen ( image_url ) image_content = image_response . read ( ) image_temp . write ( image_content ) http_message = image_response . info ( ) image_size = len ( image_content ) try : content_type = http_message . type except AttributeError : content_type = http_message . get_content_type ( ) image_file = InMemoryUploadedFile ( file = image_temp , name = image_name , field_name = 'image' , content_type = content_type , size = image_size , charset = None ) image_file . seek ( 0 ) image_temp . flush ( ) return ( image_name , image_file )
updates the user profiles image to the given image url unfortunately this is quite a pain to get right with django suggestions to improve this are welcome .