I have done a script and I want to upload a file that it generates, but when I try it I get this error:
Traceback (most recent call last):
File "/usr/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/lib/python3.6/multiprocessing/process.py", line 93, in run
self._target(*self._args, **self._kwargs)
File "/home/javi/Escritorio/ESI/Colaborador/Base de datos/proyecto/Database/sofifa.py", line 131, in sofifa_players
Do_request.upload_file(file)
File "/home/javi/Escritorio/ESI/Colaborador/Base de datos/proyecto/Database/Do_request.py", line 42, in upload_file
media = MediaFileUpload(file,'hola',mimetype='text/*',resumable=True)
NameError: name 'MediaFileUpload' is not defined
I just used the example given by the official API but it doesn't work. Here is what I've done:
SCOPES=['https://www.googleapis.com/auth/drive.appdata','https://www.googleapis.com/auth/drive']
def upload_file(file):
#file is the name of the file I want to upload
creds = None
# The file token.pickle stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)
creds = flow.run_local_server()
# Save the credentials for the next run
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
service = build('drive', 'v3', credentials=creds)
folder_id = '1JfZDcwJA3t_yLtMTJkrUEXQzHJCrchdD'
file_metadata = {
'name': file,
'parents': [folder_id]
}
media = MediaFileUpload(file,mimetype='text/*',resumable=True)
f = drive_service.files().create(body=file_metadata,media_body=media,fields='id').execute()