1

对不起我的英语不好。我尝试在谷歌驱动器(xlsx)中创建新文件并设置一些数据。但我有错误:

AttributeError: 'bytes' object has no attribute 'encode'

我的代码:

    drive = DriveBox() # return pydrive obj

    df = pd.DataFrame({'a': [1, 2], 'b': [2, 3]})
    wb = Workbook()
    writer = pd.ExcelWriter('', engine='openpyxl')
    writer.book = wb
    df.to_excel(writer)

    xmls = drive.g_drive.CreateFile({'title': 'test.xlsx',
                                     'mimeType': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'})
    xmls.SetContentString(save_virtual_workbook(wb))
    xmls.Upload()

升级版:

python 版本:3,6 回溯:

C:\Python36\python.exe C:/work/projects/project/do_api/Main.py
Main
Traceback (most recent call last):
  File "C:/work/projects/project/do_api/Main.py", line 18, in <module>
    class Main:
  File "C:/work/projects/project/do_api/Main.py", line 36, in Main
    xmls.log()
  File "C:\work\projects\project\do_api\xmsl\XmslBox.py", line 80, in log
    xmls.SetContentString(save_virtual_workbook(wb))
  File "C:\Python36\lib\site-packages\pydrive\files.py", line 155, in SetContentString
    self.content = io.BytesIO(content.encode(encoding))
AttributeError: 'bytes' object has no attribute 'encode'
4

0 回答 0