Error executing task write argument must be str not bytes

After a clean install of Windows 10 when I started to use MySQL workbench I have this error when I try to dump a database. I could not find anything about it anywhere, the only thing I find are pro...

After a clean install of Windows 10 when I started to use MySQL workbench I have this error when I try to dump a database.

I could not find anything about it anywhere, the only thing I find are problems with phyton, but nothing related with Workbench.

Output after dumping a database:

08:29:00 Dumping foo(all tables)
Error executing task write() argument must be str, not bytes
08:29:01 Export of b'C:\Users\erick\Documents\dumps\Dump20210121 (2).sql' has finished

And the output file is in blank, some ideas?

asked Jan 21, 2021 at 15:36

Erick Amezcua's user avatar

2

You can disable (uncheck) the option create schema. It is annoying but it works.

answered Feb 15, 2021 at 22:53

magallanes's user avatar

magallanesmagallanes

6,4254 gold badges53 silver badges54 bronze badges

4

If you have the latest MySQL Workbench (8.0.23), just uninstall and install MySQL Workbench 8.0.20. That worked for me.

answered Jan 22, 2021 at 23:38

RodriT91's user avatar

5

Another workaround to this issue is to edit wb_admin_export.py.

In dump_to_folder (line 1679) replace

self.out_pipe = open(path,"w")

with

self.out_pipe = open(path,"wb")

In dump_to_file (line 1957) replace

self.out_pipe = open(self.path,"w")

with

self.out_pipe = open(self.path,"wb")

answered Feb 10, 2021 at 17:37

cl0ne's user avatar

cl0necl0ne

3005 silver badges13 bronze badges

4

If you a using version 8.0.23, update to 8.0.25 or above…. it will fix this issue

answered Sep 11, 2022 at 10:40

hamil.Dev's user avatar

hamil.Devhamil.Dev

891 silver badge9 bronze badges

1

#mysql #mysql-workbench

#mysql #mysql-workbench

Вопрос:

После чистой установки Windows 10, когда я начал использовать MySQL workbench, у меня возникает эта ошибка при попытке создать дамп базы данных.

Я нигде ничего не мог найти об этом, единственное, что я нахожу, это проблемы с phyton, но ничего не связано с Workbench.

Вывод после сброса базы данных:

 08:29:00 Dumping foo(all tables)
Error executing task write() argument must be str, not bytes
08:29:01 Export of b'C:UserserickDocumentsdumpsDump20210121 (2).sql' has finished
 

И выходной файл пустой, какие-то идеи?

Комментарии:

1. bugs.mysql.com/bug.php?id=102320

2. Исправлено в 8.0.25 .

Ответ №1:

Вы можете отключить (снять флажок) опцию создать схему. Это раздражает, но это работает.

Комментарии:

1. MySQL Workbench полон сюрпризов

2. Также раздражает: сбой всей резервной копии в целевой системе из-за «ОШИБКИ 1049 (42000): неизвестная база данных», поскольку не было СХЕМЫ СОЗДАНИЯ.

3. Да! это спасло меня от досадной проблемы. Спасибо

4. Черт возьми, я просто закрыл MySQL Workbench и перезагрузил его, и проблема исчезла. Win 10, Workbench 8.0.23.

Ответ №2:

Если у вас установлена последняя версия MySQL Workbench (8.0.23), просто удалите и установите MySQL Workbench 8.0.20. Это сработало для меня.

Комментарии:

1. Я использую Linux Mint 20.1, и понижение исправило эту проблему.

2. Это! Решена моя проблема. Спасибо!

3. Решаемая в версии Workbench для Windows.

4. Только что возникла эта проблема в версии 8.0.23 и обновлена до 8.0.25 (которая на данный момент является последней версией). Теперь проблема исчезла, и экспорт создается нормально (с помощью инструкций CREATE)

5. Понижение рейтинга не всегда возможно, вы можете попробовать сделать это в Arch Linux.

Ответ №3:

Другим решением этой проблемы является редактирование wb_admin_export.py .

В dump_to_folder (строка 1679) заменить

 self.out_pipe = open(path,"w")
 

с

 self.out_pipe = open(path,"wb")
 

В dump_to_file (строка 1957) заменить

 self.out_pipe = open(self.path,"w")
 

с

 self.out_pipe = open(self.path,"wb")
 

Комментарии:

1. Мне пришлось изменить w wb в двух строках: self.out_pipe = open(path,"w") внутри функции dump_to_folder() и self.out_pipe = open(self.path,"w") внутри функции dump_to_file() .

2. @carlosrafaelgn это именно те функции, на которые я ссылался в ответе 😉

3. Действительно, вы правы! Я просто добавил комментарий, чтобы помочь кому-то, кто просто проигнорировал номера строк (как и я), дважды нажал «Найти далее» и в итоге нашел только одно вхождение, потому что в одной строке у нас есть open(path,"w") , а в другой у нас есть open(self.path,"w") 😅

4. @carlosrafaelgn вы определенно правы, я отредактировал ответ 🙂

You try writing data in bytes to a file. However, you receive a message, which is TypeError: write() argument must be str, not bytes in Python. Don’t worry because this is a common error that most new Python developers get. This article will explain the cause and solutions to fix it!

You get the message error: “TypeError: write() argument must be str, not bytes” in Python when trying to write data in bytes to your text file.

In the sample below, you want to write the bytes: b'learnshareit.com' to the file test.txt.

with open('test.txt', 'w') as testFile:
    testFile.write(b'learnshareit.com')

The message will show:

testFile.write(b'learnshareit.com')    
  TypeError: write() argument must be str, not bytes

It is easy to understand. Python requires you to use the Binary Mode before you write bytes.

The 2nd parameter in the open() function is 'w'. This allows you to write strings to your file only.

Solution for this error

The solution for the error is very easy. As mentioned, you must use the Binary Mode to write a byte to the file. 

All you need to do is changing the 2nd parameter in the open() function from 'w'  to 'wb'. 'wb' stands for “write byte”. It means that you are “writing in the Binary Mode”. After making the change, you will see no error from your Python program anymore.

In the sample below, Python starts writing the bytes: b'learnshareit.com' to the file test.txt:

# Open the test.txt in the Binary Mode
with open('test.txt', 'wb') as testFile:
    testFile.write(b'learnshareit.com')

Open the test.txt file, and you will see the work done:

learnshareit.com

Please remember that we read and write data as ‘bytes’ in the Binary Mode. Python does not make any changes to the data as it is written in the file. Therefore, the Binary Mode should only be used for any file that does not contain text.

If you want to open a binary file, use 'rb' instead of 'r' in the 2nd parameter of the open() function.

You can see the sample code below:

# Open the test.txt in the Binary Mode
with open('test.txt', 'wb') as testFile:
    testFile.write(b'learnshareit.com')

# Read the test.txt in the Binary Mode
with open('test.txt', 'rb') as testFile:
    print(testFile.read())

Summary

The TypeError: write() argument must be str, not bytes in Python occurs if you write bytes to a text file. The cause of this error is that you put the ‘w’ in the 2nd parameter of the open() function. Just replace the 'w' with 'wb', and your Python program will work properly!

Maybe you are interested:

  • TypeError: unsupported operand type(s) for /: list and int
  • TypeError: list indices must be integers or slices not float
  • Unsupported operand type(s) for +: ‘PosixPath’ and ‘str’

I am William Nguyen and currently work as a software developer. I am highly interested in programming, especially in Python, C++, Html, Css, and Javascript. I’ve worked on numerous software development projects throughout the years. I am eager to share my knowledge with others that enjoy programming!

Comments

@fschulze

obestwalter

added a commit
to obestwalter/tox-reproducers
that referenced
this issue

Dec 15, 2017

@obestwalter

@obestwalter
obestwalter

added
the

needs:reproducer

ideally a failing test marked as xfail. If that is not possible exact instructions to reproduce

label

Dec 15, 2017

fschulze

added a commit
to fschulze/tox
that referenced
this issue

Jan 11, 2018

@fschulze

…revent str vs bytes issues.

fschulze

added a commit
to fschulze/tox
that referenced
this issue

Jan 11, 2018

@fschulze

…revent str vs bytes issues.

@obestwalter
obestwalter

removed
the

needs:reproducer

ideally a failing test marked as xfail. If that is not possible exact instructions to reproduce

label

Jan 23, 2018

@tox-dev
tox-dev

locked and limited conversation to collaborators

Jan 14, 2021

Понравилась статья? Поделить с друзьями:
  • Error executing task on client java lang nullpointerexception null
  • Error executing task on chunk source main thread executor for minecraft overworld
  • Error executing task java util concurrent executionexception java lang assertionerror trap
  • Error executing sql statement
  • Error executing sql script