google-code-export / gdata-python-client

Automatically exported from code.google.com/p/gdata-python-client
1 stars 0 forks source link

youtube InsertVideoEntry can't handle a file_handle #607

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Init a YouTubeSerivce client
2. Do the following:

In [173]: fh = open('/Users/mfogel/temp.mp4')
In [174]: group = gdata.media.Group(title=gdata.media.Title(text="my title"), 
category=category)

In [175]: video_entry = gdata.youtube.YouTubeVideoEntry(media=group)
In [176]: new_entry = youtube_client.InsertVideoEntry(video_entry, fh)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/Users/mfogel/.virtualenvs/app/lib/python2.7/site-packages/django/core/managemen
t/commands/shell.pyc in <module>()
----> 1 new_entry = client.InsertVideoEntry(video_entry, fh)

/Users/mfogel/.virtualenvs/app/lib/python2.7/site-packages/gdata/youtube/service
.pyc in InsertVideoEntry(self, video_entry, filename_or_handle, 
youtube_username, content_type)
    640         name = filename_or_handle.name
    641       mediasource = gdata.MediaSource(file_handle, content_type,
--> 642           content_length=file_handle.len, file_name=name)
    643     else:
    644       raise YouTubeError({'status':YOUTUBE_INVALID_ARGUMENT, 'body':

AttributeError: 'file' object has no attribute 'len'

What is the expected output? What do you see instead?

gdata is looking for a '.len' attribute on a file handle that isn't there.

Note this is handled elsewhere in the gdata codebase by allowing an optional 
content_length keyword (picasa upload an image)

Also, at on line 634 there's an "import StringIO" that is unused... was this 
meant to build a wrapper around a file handle?

What version of the product are you using?

2.0.16

Please provide any additional information below.

Original issue reported on code.google.com by m...@fogel.ca on 10 Apr 2012 at 11:58

GoogleCodeExporter commented 9 years ago
I see the same behavior in my application. 
gdata is looking for a attribute len which it does not find and gives an 
Attribute Error. 

                        text='Education',
                        label='Education')],
                )

            extension = ExtensionElement('accessControl', namespace=YOUTUBE_NAMESPACE, attributes={'action': 'list', 'permission': 'denied'})

            video_entry = gdata.youtube.YouTubeVideoEntry(media=my_media_group, extension_elements=[extension])

            entry = yt_service.InsertVideoEntry(video_entry, video.file)
    ...

▶ Local vars
/home/quietrags/lib/python2.7/gdata/youtube/service.py in InsertVideoEntry

          if hasattr(filename_or_handle, 'seek'):
            filename_or_handle.seek(0)
          file_handle = filename_or_handle
          name = 'video'
          if hasattr(filename_or_handle, 'name'):
            name = filename_or_handle.name
          mediasource = gdata.MediaSource(file_handle, content_type,
              content_length=file_handle.len, file_name=name)
        else:
          raise YouTubeError({'status':YOUTUBE_INVALID_ARGUMENT, 'body':
              '`filename_or_handle` must be a path name or a file-like object',
              'reason': ('Found %s, not path name or object '

                         'with a .read() method' % type(filename_or_handle))})

        upload_uri = '%s/%s/%s' % (YOUTUBE_UPLOAD_URI, youtube_username,

Original comment by quietr...@gmail.com on 25 Oct 2012 at 4:38