davidstrauss / google-drive-recursive-ownership

Tool to recursively give away file and document ownership to another user.
MIT License
268 stars 68 forks source link

Support UTF-8 filenames/folders #26

Open Nottt opened 5 years ago

Nottt commented 5 years ago

The current script will fail with lots of folders and filenames.

I can get past the UnicodeEncodeError: with this:

reload(sys)
sys.setdefaultencoding('utf-8')

But then it goes on but nothing is shared/changed

python transfer.py "Téáóçãú" backup@.email false
Changing all files at path "Téáóçãú" to owner "backup@.email"
Prefix: [u'T\xe9\xe1\xf3\xe7\xe3\xfa']
Use this link for authorization: link
Verification code: code
User backup@.email is permission ID 05411747774099128436.
Gathering file listings for prefix []...
Folder: Téáóçãú ([], 1CkIpP7rvMP5R1AKaLNEzjRhMGKr2tcPf)
Gathering file listings for prefix [u'T\xe9\xe1\xf3\xe7\xe3\xfa']...
Folder: solto ([], 1aHUnS8GV4TGI_j5CAhuAOHYl4-5kwT8s)

Any chance we can get this? This is still the best method to change permissions with google drive but it chokes with lots of characters :(

davidstrauss commented 5 years ago

Do you have any guidance on the best way to add the support? I'm happy to look at Pull Requests, but it's been years since I've looked deeply at the Google Drive APIs that would be applicable to this situation.

Nottt commented 5 years ago

It's not the Google Drive API, it's a python language issue. Python is notorious for sucking with UTF-8.

I have the script working locally now as far as changing ownership and everything, but you are still printing this wrong:

Prefix: [u'T\xe9\xe1\xf3\xe7\xe3\xfa']

I can do a PR if you want, but I'm no developer by any means and the quick stuff I found to try to fix this didn't work.

Previously I thought the script didn't work, but I didn't have any files in that folder so that's why nothing was happening. I thought it would just change the root folder permission too.

davidstrauss commented 5 years ago

Thanks. It would still be helpful to know how you're working around the issue, even if it's not the right thing to commit to the code here.

Nottt commented 5 years ago

I just added this after the imports

reload(sys)
sys.setdefaultencoding('utf-8')
lesantos commented 4 years ago

I had the same problem, but I noticed that the error is only when printing the drive_item['title'], so I commented the prints and it is working fine. I'd tried to fix with some unicode magic, but I failed. I read it should be simpler with python 3.

davidstrauss commented 4 years ago

From @Nottt's comment:

reload(sys) sys.setdefaultencoding('utf-8')

I don't have much time to devote to this project, but I'm happy to take a pull request that adds this.