Drive download error: UnboundLocalError: local variable 'download_url' referenced before assignment

577 views
Skip to first unread message

Rick Burgess

unread,
Jun 30, 2014, 1:17:05 PM6/30/14
to google-ap...@googlegroups.com
Hello. I'm attempting to download the contents of each user's Drive/Docs through gam with the following command: 

gam user "user...@mydomain.com" get drivefile query "'me' in owners" format microsoft targetfolder "C:\test"



It produces this output:

Searching for files with query: "'me' in owners"...
 got 139 files...
Downloading Google Doc: C:\test/SLC - from User 2014
Traceback (most recent call last):
  File "gam.py", line 7353, in <module>
  File "gam.py", line 2339, in downloadDriveFile
UnboundLocalError: local variable 'download_url' referenced before assignment

Any ideas what's going on and how I can proceed?

Matt S

unread,
Jul 1, 2014, 9:33:29 AM7/1/14
to google-ap...@googlegroups.com
There appear to be a few bugs in this function.  There is a similar error with the 'export_formats' variable.  Both need to be assigned at the beginning of the function.  I was trying to fix it myself but was having trouble compiling/running the code.  Was trying to get help here: https://groups.google.com/forum/#!topic/google-apps-manager/xpPu7kSoFqM

Hopefully one of the devs will see this.  I tried emailing one of them too (jay0lee) but didn't get a response.  Couldn't find the other's email address.

-Matt

Jay Lee

unread,
Jul 4, 2014, 7:24:07 AM7/4/14
to google-ap...@googlegroups.com
This is fixed in GAM 3.3:


@Matt S: as far as compiling GAM, you need to install the pyOpenSSL library. There may be other dependencies. I use the build.bat script to put all the bits together. It's been awhile but if I ever rebuild my Windows machine I'll try to document the process.

Jay

Ed Hillis

unread,
Jul 6, 2014, 1:20:53 AM7/6/14
to google-ap...@googlegroups.com
I'm seeing this error in GAM 3.3 64-bit windows version

Downloading Google Doc: folder/xyz
Traceback (most recent call last):
  File "gam.py", line 7177, in <module>
  File "gam.py", line 2275, in downloadDriveFile
UnboundLocalError: local variable 'download_url' referenced before assignment

Ed

Jay Lee

unread,
Jul 6, 2014, 10:50:19 AM7/6/14
to google-ap...@googlegroups.com
What type of document is folder/xyz? Can someone share a problematic file with me as I'm unable to reproduce the issue otherwise. Share it with ad...@jay.powerposters.org


Jay Lee


--
You received this message because you are subscribed to the Google Groups "Google Apps Manager" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To post to this group, send email to google-ap...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-apps-manager.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/35defef8-bf5d-4609-b2be-d790bf802b7c%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Rick Burgess

unread,
Jul 6, 2014, 1:14:55 PM7/6/14
to google-ap...@googlegroups.com
Interestingly, I tried the same command running the x86 version and it works.


--

Ed Hillis

unread,
Jul 6, 2014, 9:44:04 PM7/6/14
to google-ap...@googlegroups.com
It turns out it's a folder. The user owns the folder, but she only owns a few of the files in the folder. The rest are owned by others in the organization. I'm working on backing up some users' files, and this is one of the users. I can't share it without her permission, but may be able to arrange that. 

Thanks,
Ed



Jay Lee


To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-manager+unsub...@googlegroups.com.

To post to this group, send email to google-ap...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-apps-manager.

Jay Lee

unread,
Jul 7, 2014, 7:16:47 AM7/7/14
to google-ap...@googlegroups.com
Don't try to download folders, they don't actually contain any content. I'll add code to skip over them in the next GAM release but for now you should be skipping over them with your query. The OP query should be:

gam user "user...@mydomain.com" get drivefile query "'me' in owners and mimeType != 'application/vnd.google-apps.folder'" format microsoft targetfolder "C:\test"


Jay Lee


To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.

To post to this group, send email to google-ap...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-apps-manager.

Ed Hillis

unread,
Jul 8, 2014, 4:23:33 PM7/8/14
to google-ap...@googlegroups.com
That worked. Thanks!

Ed



Jay Lee


Thanks,
Ed



Jay Lee


To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-manager+unsubscribe...@googlegroups.com.
To post to this group, send email to google-ap...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Apps Manager" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-manager+unsub...@googlegroups.com.
To post to this group, send email to google-ap...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-apps-manager.

Matt S

unread,
Jul 9, 2014, 8:32:54 AM7/9/14
to google-ap...@googlegroups.com
Thanks for the update!  Much appreciated.  Unfortunately I came across another issue:

Running the query with the folder exclusion you mentioned above I got this:

Searching for files with query: "'me' in owners and mimeType != 'application/vnd.google-apps.folder'"...

Traceback (most recent call last):

 
File "gam.py", line 7177, in <module>
 
File "gam.py", line 2225, in downloadDriveFile
 
File "gam.py", line 1844, in doDriveSearch
 
File "gam.py", line 434, in callGAPIpages
 
File "gam.py", line 374, in callGAPI
 
File "oauth2client\util.pyo", line 132, in positional_wrapper
 
File "apiclient\http.pyo", line 716, in execute
 
File "oauth2client\util.pyo", line 132, in positional_wrapper
 
File "oauth2client\client.pyo", line 490, in new_request
 
File "httplib2\__init__.pyo", line 1593, in request
 
File "httplib2\__init__.pyo", line 1396, in _request
 
File "httplib2\__init__.pyo", line 448, in _updateCache
 
File "httplib2\__init__.pyo", line 715, in set
IOError: [Errno 2] No such file or directory: 'C:\\Users\\userprofile\\Desktop\\gam\\gamcache\\www.googleapis.com,drive,v2,files,q=%27me%27+in+owners+and+m
imeType+%21%3D+%27application%2Fvnd.google-apps.folder%27&fields=nextPageToken%2Citems%28id%29&alt=json&prettyPrint=false&maxResults=1000,hashremovedforsecurity'


Then without the folder exclusion I got this:

Searching for files with query: "'me' in owners"...

 got
589 files...
Downloading Google Doc: C:\Users\userprofile\Desktop\gam\_GoogleDrive-userfolder/Senior Seminar.odt
Downloading: C:\Users\userprofile\Desktop\gam\_GoogleDrive-userfolder/WhatisGovernment.pdf of 8mb bytes
Traceback (most recent call last):

 
File "gam.py", line 7177, in <module>
 
File "gam.py", line 2275, in downloadDriveFile
 
File "oauth2client\util.pyo", line 132, in positional_wrapper
 
File "oauth2client\client.pyo", line 490, in new_request
 
File "httplib2\__init__.pyo", line 1593, in request
 
File "httplib2\__init__.pyo", line 1396, in _request
 
File "httplib2\__init__.pyo", line 448, in _updateCache
 
File "httplib2\__init__.pyo", line 715, in set
IOError: [Errno 2] No such file or directory: 'C:\\Users\\userprofile\\Desktop\\gam\\gamcache\\doc-14-3c-docs.googleusercontent.com,docs,securesc,hashesremovedforsecurity'

It did download the first file, "Senior Seminar.odt".

Same results both with "format Microsoft" and without.

Matt S

unread,
Jul 9, 2014, 8:36:33 AM7/9/14
to google-ap...@googlegroups.com
Upon searching the error I found this thread: https://code.google.com/p/google-apps-manager/issues/detail?id=170 which talks about the nocache.exe file.  That did fix the above issue.

Gustavo Aristi

unread,
Dec 31, 2014, 12:05:28 PM12/31/14
to google-ap...@googlegroups.com
I am trying to do something similar in bulk. 

However with this method all files from multiple users end up all mixed up in the target folder. Is there an argument I can use to have GAM create independent folders for each user's Drive files?


gam csv userList.csv gam user ~email get drivefile query "'me' in owners" format microsoft targetfolder "C:\TEST"


Thanks for the help!

+KimNilsson

unread,
Jan 2, 2015, 12:01:05 PM1/2/15
to google-ap...@googlegroups.com
Most likely!
Put unique folders in your CSV and set the final option targetfolder as a variable, like the other CSV variables.
Something like this.

gam csv userList.csv gam user ~email get drivefile query "'me' in owners" format microsoft targetfolder ~folder

Rajesh Sadasivan

unread,
May 8, 2020, 2:11:16 AM5/8/20
to GAM for G Suite
Python has lexical scoping by default, which means that although an enclosed scope can access values in its enclosing scope, it cannot modify them (unless they're declared global with the global keyword). A closure binds values in the enclosing environment to names in the local environment. The local environment can then use the bound value, and even reassign that name to something else, but it can't modify the binding in the enclosing environment. UnboundLocalError happend because when python sees an assignment inside a function then it considers that variable as local variable and will not fetch its value from enclosing or global scope when we execute the function. To modify a global variable inside a function, you must use the global keyword.



Ross Scroggs

unread,
May 8, 2020, 8:34:15 AM5/8/20
to google-ap...@googlegroups.com
Rajesh,

It would be helpful to see the command you entered and the error message.

On May 7, 2020, at 11:11 PM, Rajesh Sadasivan <rajesh...@gmail.com> wrote:

Python has lexical scoping by default, which means that although an enclosed scope can access values in its enclosing scope, it cannot modify them (unless they're declared global with the global keyword). A closure binds values in the enclosing environment to names in the local environment. The local environment can then use the bound value, and even reassign that name to something else, but it can't modify the binding in the enclosing environment. UnboundLocalError happend because when python sees an assignment inside a function then it considers that variable as local variable and will not fetch its value from enclosing or global scope when we execute the function. To modify a global variable inside a function, you must use the global keyword.




--
You received this message because you are subscribed to the Google Groups "GAM for G Suite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/e256664c-561d-4c87-960c-92c978283bde%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages