httplib2 vs. YouTube Upload API v3

181 views
Skip to first unread message

Soeren Balko

unread,
Sep 1, 2015, 1:03:52 AM9/1/15
to Google App Engine
Hi,

I'm running into weird issues with httplib2 when following the instructions for resumable uploads to YouTube (see here: https://developers.google.com/youtube/v3/guides/using_resumable_upload_protocol).

Their very first server roundtrip creates a video resource and returns a "Location" response header, which is the upload URL to send the actual video file. That works well and when I invoke this service using cURL like so:

curl -X POST \
     --verbose \
     -H "Authorization: Bearer ..." \
     -H "Content-Type: application/json; charset=UTF-8" \
     -H "X-Upload-Content-Type: video/*" \
     -H "X-Upload-Content-Length: 500" \
     -d '{"snippet": {"title": "foo"}, "status": {"privacyStatus": "unlisted"}}' \

...it works as desired and gives me a HTTP/200 and the aforementioned "Location" response header. I tried to mimic that in a GAE Python app, using the httplib2 library. Here is what I do:

http = httplib2.Http()
credentials.authorize(http)
                    
body = simplejson.dumps({
'snippet': {
'title': 'foo',
'description': 'bar'
},
'status': {
'privacyStatus': 'unlisted'
}
})
                    
response, content = http.request(
uri = 'https://www.googleapis.com/upload/youtube/v3/videos?uploadtype=resumable&part=snippet%2Cstatus'
method = 'POST',
body = body, 
headers = {
'X-Upload-Content-Length': str(size),
'X-Upload-Content-Type': 'video/*',
'Content-Type': 'application/json; charset=UTF-8'
}

)


However, that request returns a HTTP/400 with a body that says:


{

 "error": {

  "errors": [

   {

    "domain": "global",

    "reason": "badContent",

    "message": "Media type 'application/json; charset=UTF-8' is not supported. Valid media types: [video/*, application/octet-stream]"

   }

  ],

  "code": 400,

  "message": "Media type 'application/json; charset=UTF-8' is not supported. Valid media types: [video/*, application/octet-stream]"

 }

}


That doesn't make any sense to me. Somehow, it confuses the "Content-Type" header with that "X-Upload-Content-Type" and I don't know why that is. I tried passing the HTTPS traffic through a HTTP proxy, but httplib2 does not seem to play nicely with the HTTP proxy I use (Charles). 


Ideas, anyone?


Thanks heaps,

Soeren

Nick (Cloud Platform Support)

unread,
Sep 3, 2015, 11:52:35 AM9/3/15
to Google App Engine
Hey Soeren,

Given that the issue only occurs on GAE while the equivalent HTTP using CURL is valid, this appears to be an issue in the infrastructure. Normally such a report should go in the public issue tracker, but I've handled the issue by reproducing what you saw. We're now working on diagnosing a fix or workaround, and I hope to report back soon with an update.

Sincerely,

Nick

Nick (Cloud Platform Support)

unread,
Sep 11, 2015, 4:59:46 PM9/11/15
to Google App Engine
Hey Soeren,

We're still working to figure this out, so thanks for your patience. I'll update next week with any results.

Best wishes,


Nick

On Tuesday, September 1, 2015 at 1:03:52 AM UTC-4, Soeren Balko wrote:

Nick (Cloud Platform Support)

unread,
Sep 21, 2015, 2:13:13 PM9/21/15
to Google App Engine
Hey Soeren,

Sorry for the delay. We're continuing to look into this. It appears to be related to the connection between App Engine and the Youtube API, and your initial explanation was very helpful in getting this reproduced and diagnosed. I hope to have an update soon in this thread to inform you and anybody else as to the status of this issue (hopefully resolved soon).

Best wishes,

Nick

Nick (Cloud Platform Support)

unread,
Sep 28, 2015, 5:12:52 PM9/28/15
to Google App Engine
Hey Soeren,

I've created a public issue tracker thread to keep a more formal track of this rather than just a Groups thread. Follow there to find any updates. Best of luck.

On Tuesday, September 1, 2015 at 1:03:52 AM UTC-4, Soeren Balko wrote:
Reply all
Reply to author
Forward
0 new messages