I've been racking my brain trying to figure out why I can't upload a file to google drive through the API service. I've pin pointed the issue to be related to the special character in Pokémon. If I change that to a regular e, there is no issue uploading the file.
I have already found tried the following method which works but I lose the é altogether.
.encode('ascii','ignore').decode('ascii')
Is there a way to change the encoding that the API uses to upload a file? The error I constantly get is
UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 3: ordinal not in range(128)
My sample code is listed below
from httplib2 import Http
import io
from apiclient.discovery import build
from apiclient import errors
from apiclient.http import MediaFileUpload, MediaIoBaseDownload, MediaIoBaseUpload
# If modifying these scopes, delete your previously saved credentials
# at ~/.credentials/drive-python-quickstart.json
SCOPES = 'https://www.googleapis.com/auth/drive'
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'Drive API Python Quickstart'
#performs authorization
authInst = auth(SCOPES,CLIENT_SECRET_FILE,APPLICATION_NAME)
#gets the credentials for use
credentials = authInst.getCredentials()
#sets up the drive service from which functions can be created
drive_service = build('drive', 'v3', http=credentials.authorize(Http()))
test = 'Pokémon, test, hello\nmark,john,kevin'.encode('ascii','ignore').decode('ascii')
fh = io.StringIO(test)
media = MediaIoBaseUpload(fh,
mimetype='text/csv',
resumable = False)
filename = 'csvtest'
file_metadata = {'name': filename, 'mimeType': 'application/vnd.google-apps.spreadsheet'}
file = drive_service.files().create(body=file_metadata,\
media_body=media,\
fields='id').execute()
fileID = file.get('id')
print(fileID)
Lastly, I have done this manually using the actual google Drive with a file simply containing Pokémon and I never lost the é so I feel like this must be possible.