teambott2 / youtube-api-samples

Automatically exported from code.google.com/p/youtube-api-samples
0 stars 0 forks source link

upload_video.py - TypeError: argument of type 'NoneType' is not iterable #11

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. try to upload a 200mb video file
2. it errors.
3. im sad.

What is the expected output? What do you see instead?
Uploading file... and be done.

This seems unexpected:

    if 'id' in response:
TypeError: argument of type 'NoneType' is not iterable

What version of the product are you using? On what operating system?

Please provide any additional information below.

I suspect this hasn't been tested on files that need more than one chunk.
I think it is expected too loop, but instead it errors:

  while response is None:
    try:
      print "Uploading file..."
      status, response = insert_request.next_chunk()
      if 'id' in response:

Original issue reported on code.google.com by cfkars...@gmail.com on 6 May 2014 at 7:02

GoogleCodeExporter commented 9 years ago
The sample code uses a chunksize of -1 (all at once):

https://code.google.com/p/youtube-api-samples/source/browse/samples/python/uploa
d_video.py#104

  media_body=MediaFileUpload(options.file, chunksize=-1, resumable=True)

so it never chunks, thus it never runs the chunking code, which is where this 
bug lives.

Original comment by cfkars...@gmail.com on 6 May 2014 at 9:47

GoogleCodeExporter commented 9 years ago
I'm sad too
Any fix for that?

Thanks,

Original comment by tht2401 on 29 Oct 2014 at 2:13

GoogleCodeExporter commented 9 years ago
Nope.

The same code (and bug) is also here:
https://github.com/youtube/api-samples/blob/master/python/upload_video.py#L131-L
135

I stared to work on a fix, but testing error handling is hard, so I just gave 
up and set chunksize=-1.

https://github.com/CarlFK/veyepar/blob/master/dj/scripts/youtube_v3_uploader.py#
L181

Original comment by cfkars...@gmail.com on 29 Oct 2014 at 3:15

GoogleCodeExporter commented 9 years ago
I added a simple line of code, it worked beautifully (check None for response):

      .....
      status, response = insert_request.next_chunk()
      if response is not None:
        if 'id' in response:
      ...

Original comment by tht2401 on 29 Oct 2014 at 4:20

GoogleCodeExporter commented 9 years ago
I think you moved the bug to this:

if error is not None:
print error
retry += 1
if retry > MAX_RETRIES:
exit("No longer attempting to retry.")

You don't set error, so it is still None, so retry will never get incremented, 
so it may loop forever.  

Which may be better than erroring, but still not right.  
I was hoping that by now someone would have fixed the code but I guess it isn't 
a priority. 

Original comment by cfkars...@gmail.com on 29 Oct 2014 at 4:29

GoogleCodeExporter commented 9 years ago
I haven't looked at api code but I think that response will be None until the 
last chunk is sent.
error is not None only when we have an exception from 
insert_request.next_chunk()
The sample code has MAX_RETRIES so it won't loop forever.

Original comment by tht2401 on 29 Oct 2014 at 4:39

GoogleCodeExporter commented 9 years ago
ah right, I see what you are saying. 

pretty please submit a pull request over on 
https://github.com/youtube/api-samples (you can do it by editing the code right 
there, click the edit link that takes you to
https://github.com/youtube/api-samples/edit/master/python/upload_video.py

Original comment by cfkars...@gmail.com on 29 Oct 2014 at 4:46

GoogleCodeExporter commented 9 years ago
https://github.com/youtube/api-samples/pull/18

Original comment by tht2401 on 29 Oct 2014 at 4:58