Ошибка типа: объект 'str' не поддерживает назначение элементов google api - PullRequest
0 голосов
/ 31 марта 2020

Итак, я хотел бы создать приложение, которое загружает файл на диск Google, приложение создает текстовый файл, набрав Переменные. Так что приложение работает, но если я попытаюсь связать его с Google Drive, оно просто не загрузится. Я новичок в Python (начался как неделя go), поэтому я хотел бы получить положительный ответ.

Полный журнал консоли:

Authentication successful.
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Akush\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
    return self.func(*args)
  File "C:/Users/Akush/PycharmProjects/untitled/importer.py", line 15, in importfilestogoogle
    file1.Upload(c+'.txt') # Upload the file.
  File "C:\Users\Akush\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pydrive\files.py", line 285, in Upload
    self._FilesInsert(param=param)
  File "C:\Users\Akush\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pydrive\auth.py", line 75, in _decorated
    return decoratee(self, *args, **kwargs)
  File "C:\Users\Akush\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pydrive\files.py", line 364, in _FilesInsert
    param['body'] = self.GetChanges()
TypeError: 'str' object does not support item assignment

Код, который сгенерировал ошибка:

import tkinter as tk
import sys
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
import random


def importfilestogoogle():
    gauth = GoogleAuth()
    gauth.LocalWebserverAuth()
    drive = GoogleDrive(gauth)

    file1 = drive.CreateFile({"mimeType": "text/csv", "parents": [{"kind": 
    "drive#fileLink", "id": random.randrange(1,None)}]})
    file1.SetContentFile(c+'.txt')
    file1.Upload(c+'.txt') # Upload the file.

def press2(event):
    global c
    c = file_entry.get()
    file_entry.delete(0,'end')
    screen2.destroy()

def getnamefile():
    global c
    c = file_entry.get()
    file_entry.delete(0,'end')
    screen2.destroy()


def NameFilescren():
    global screen2
    global file_entry
    screen2 = tk.Toplevel(root1)
    screen2.title('Nazwa Pliku')
    screen2.geometry('240x80')
    screen_label = tk.Label(screen2,text='Wprowadź nazwe:')
    screen_label.pack()
    file_entry = tk.Entry(screen2)
    file_entry.pack()
    file_button = tk.Button(screen2, text='Kliknij 
    tutaj',command=getnamefile)
    file_button.pack()
    screen2_label = tk.Label(screen2, text='Plik tekstowy zapisuje się w 
    folderze aplikacji')
    screen2_label.pack()
    submit2 = tk.Button(root1, command=press2)
    screen2.bind('<Return>', press2)



def quit(event):
    sys.exit()
        # po naciśnięciu przycisku(button) wykonuje daną czynność
def click():
    a = e.get()
    e.delete(0, 'end')
    f = open(c +'.txt', 'a')
    f.write("\n")
    f.write(a)
    f.close()

    # po naciśnięciu klawisza na klawiaturze wykonuje dana czynność
def press(event):
    a = e.get()
    e.delete(0, 'end')
    f = open(c + '.txt', 'a')
    f.write('\n')
    f.write(a)
    f.close()

def window2():
    global e
    global root1
    global label
    global label2

    root1 = tk.Tk()
    label = tk.Label(root1, text='Wprowadź dane :')
    label.place(x=50, y=10)
    e = tk.Entry(root1)
    e.place(x=175, y=10)
    button = tk.Button(root1, text='------>', command=click)
    button.place(x=145, y=50)
    submit = tk.Button(root1, command=press)
    exit = tk.Button(root1, command=quit)
    root1.bind('<Return>', press)
    root1.bind('<Escape>', quit)
    button2 = tk.Button(root1, text='Wybierz nazwe Pliku', 
    command=NameFilescren)
    button2.place(x=5,y=315)
    button3 = tk.Button(root1, text='Upload''uj do Google Drive', 
    command=importfilestogoogle)
    button3.place(x=200, y=315)
    root1.title('Przechowywacz danych')
    root1.geometry('350x350')
    root1.mainloop()
window2()
...