Got 503 error while downloading multipart using Google Drive sdk v2

I have a 503 error that says the "Service is unavailable" error when I tried to send multi-page content to a Google drive via sdk v2. I got the empty content of the response and the header as shown below:

{'content-length': '0', 'x-google-cache-control': 'remote-fetch', 'expires': 'Fri, 01 Jan 1990 00:00:00 GMT', 'server': 'HTTP Upload Server Built on Jun 14 2012 02:12:09 (1339665129)', 'via': 'HTTP/1.1 GWA', 'pragma': 'no-cache', 'cache-control': 'no-cache, no-store, must-revalidate', 'date': 'Tue, 03 Jul 2012 23:12:09 GMT', 'content-type': 'text/html; charset=UTF-8'}

Here is what I posted:

POST /upload/drive/v2/files?uploadType=multipart

Authorization: Bearer <Access token>
Content-Length: <length>
Content-Type: multipart/related; boundary="<a base64 encoded guid>"

--<a base64 encoded guid>
Content-Type: application/json

{"title": "test.jpg", "mimeType":"image/jpeg", "parents":[]}
--<a base64 encoded guid>
Content-Type: image/jpeg
Content-Transfer-Encoding: base64

<base64 encoded binary data>
--<a base64 encoded guid>--

Did I do something wrong? I can successfully run POST to create metadata, and then PUT with uploadType = media to update, but I do not want to make two API calls.

Any idea?

+1
source share
2 answers

Probably not. Error 503 simply indicates the server is for repair or something else. It is minimally able to respond with a 503 error, but basically it works. Read this if you want to know more:

http://www.checkupdown.com/status/E503.html
+1
source

: ...

url = 'https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart'

boundary = base64.b64encode(uuid.uuid4().bytes)
parts = []
parts.append('--' + boundary)
parts.append('Content-Type: application/json')
parts.append('')
parts.append(json.dumps({
    'title': name,
    'mimeType': 'image/jpeg',
    'parents': [{
        'kind': 'drive#file',
        'id': folderId
        }] if folderId else []
    }))
parts.append('--' + boundary)
parts.append('Content-Type: image/jpeg')
parts.append('Content-Transfer-Encoding: base64')
parts.append('')
parts.append(base64.b64encode(content))
parts.append('--' + boundary + '--')
parts.append('')
body = '\r\n'.join(parts)

headers = {
    'Content-Type': 'multipart/related; boundary="%s"' % boundary,
    'Content-Length': str(len(body)),
    'Authorization': 'Bearer %s' % access_token
    }
response = urlfetch.fetch(url, payload=body, method='POST', headers=headers)
assert response.status_code == 200, '%s - %s' % (response.status_code, response.content)
r = json.loads(response.content)
+1

All Articles