Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uploading a file to google docs via a Python script

I'm trying to upload a backup file from my server to my Google storage in a Python script. The backup file is an encrypted zip file (gpg file). It connects successfully, but fails transferring the file which the following error:

Traceback (most recent call last):
  File "backup.py", line 37, in <module>
    entry = gd_client.Upload(ms, 'Backup.gpg', folder_or_uri=uri)
  File "/usr/local/lib/python2.6/dist-packages/gdata/docs/service.py", line 306, in Upload
    folder_or_uri)
  File "/usr/local/lib/python2.6/dist-packages/gdata/docs/service.py", line 161, in _UploadFile
    converter=gdata.docs.DocumentListEntryFromString)
  File "/usr/local/lib/python2.6/dist-packages/gdata/service.py", line 1236, in Post
    media_source=media_source, converter=converter)
  File "/usr/local/lib/python2.6/dist-packages/gdata/service.py", line 1358, in PostOrPut
    'reason': server_response.reason, 'body': result_body}
gdata.service.RequestError: {'status': 400, 'body': 'Invalid request URI', 'reason': 'Bad Request'}

Here is my code:

import os
import sys
import gdata.docs
import gdata.docs.service
import gdata.docs.client

gd_client = gdata.docs.service.DocsService()
gd_client.ClientLogin('[email protected]', 'mypassword')

uri = '%s?convert=false' % gdata.docs.client.DOCLIST_FEED_URI

f = open('backup.zip.gpg')
ms = gdata.MediaSource(file_handle=f, content_type='application/octet-stream', content_length=os.path.getsize(f.name))
entry = gd_client.Upload(ms, 'Backup.gpg', folder_or_uri=uri)

It's possible that the file is just too big (56mb), and I can't use Google Docs storage this way. I'd hope for a more explicit error message if this was the case though. I'm wondering if it's a problem with my saying 'convert=false'. It's a Google Apps account that I'm using.

like image 219
Dan Avatar asked Oct 10 '22 13:10

Dan


1 Answers

Uploading files of any type are only allowed for Google Apps for Business accounts. A regular account cannot upload this filetype. See this link from the Google Docs API.

like image 159
serk Avatar answered Oct 18 '22 17:10

serk