Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetSharedWithAnyoneDriveACLs.py does not handle special chars #21

Open
natesonline opened this issue Oct 9, 2024 · 11 comments
Open

GetSharedWithAnyoneDriveACLs.py does not handle special chars #21

natesonline opened this issue Oct 9, 2024 · 11 comments

Comments

@natesonline
Copy link

Google Drive filenames allow lots of special characters, the python script fails with the below if it runs into one. Ran into A with a macron, some alt code emote, etc.

UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f930' in position 100: character maps to

@taers232c
Copy link
Owner

taers232c commented Oct 9, 2024 via email

@taers232c
Copy link
Owner

taers232c commented Oct 9, 2024 via email

@natesonline
Copy link
Author

Windows Key + period key brings up Windows Emoji keyboard. I guess Google accepts it. I think I overwrote my original output CSV with my manual removal of spec chars. Let me see if I can dig it up quick and share some samples. I'll get back to you.

@taers232c
Copy link
Owner

taers232c commented Oct 9, 2024 via email

@natesonline
Copy link
Author

example.spec.chars.csv
Here's 3 that I pulled and hopefully censored enough.

@taers232c
Copy link
Owner

taers232c commented Oct 9, 2024 via email

@natesonline
Copy link
Author

censored,1TDsEAvzKVXBgd4yanSYL4,BIF MAMA OUTLINE,application/vnd.google-apps.document,id:anyoneWithLink,reader,False File "C:\Users\user\Downloads\GetSharedWithAnyoneDriveACLs.py", line 67, in <module> outputCSV.writerow({'Owner': row['owners.0.emailAddress'], ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 'driveFileId': row['id'], ^^^^^^^^^^^^^^^^^^^^^^^^^ ...<3 lines>... 'role': row[f'permissions.{permissions_N}.role'], ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 'allowFileDiscovery': allowFileDiscovery}) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\csv.py", line 226, in writerow return self.writer.writerow(self._dict_to_list(rowdict)) ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f930' in position 100: character maps to <undefined>

@taers232c
Copy link
Owner

Try this, GAM is now powerful enough to not need the script

# Get Shared witn Anyone ACLS                                                                                                                                                                                                                                                                                               
gam config auto_batch_min 1 num_threads 10 redirect csv ./SharedWithAnyonePerms.csv multiprocess redirect stderr - multiprocess  all users print filelist fields id,name,basicpermissions,mimetype query "(visibility='anyoneCanFind' or visibility='anyoneWithLink')" pm type anyone em pmfilter oneitemperrow

# If desired, delete the ACLs                                                                                                                                                                                                                                                                                               
gam csv SharedWithAnyonePerms.csv gam user "~Owner" delete drivefileacl "~id" "id:~~permission.id~~"

@natesonline
Copy link
Author

Great stuff, tested on my end. Works well. Unfortunately, I'm running only against suspended users and have already deleted the special char files, so in reality I've only tested the new code in GAM, nothing specific to the reported issue with special chars.

@taers232c
Copy link
Owner

taers232c commented Oct 10, 2024 via email

@natesonline
Copy link
Author

Sent you an email.

Below is GAM output you requested that I realized I missed. This is the filename for the \U0001f930 .

gam user [email protected] show fileinfo 1nsSIk7MmbSLuG80 fields id,name

User: [email protected], Show 1 Drive File/Folder
Drive File: **** - ***- BIG MAMA OUTLINE 🤰 (1nsSIk7MmbSLuG80)
id: 1nsSIk7MmbSLuG80
name: **** - ***- BIG MAMA OUTLINE 🤰

I did forget that I could just re-add the ACL to one of the problem files. So I did that and ran the two commands you mentioned against one same file with the \U0001f930. Everything ran fine no errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants