Skip to content

Chapter 4 - Vision / Drawing detection - Issue with train_drawing_classifier.py #2

@andrefrank

Description

@andrefrank

Dear authors,

running the script train_drawing_classifier.py on a Python 3.6 console generates an error
similar to:

'bitmap_file.write' doesn't accept 'bytes' to write.

with open(bitmap_directory + bitmap_filename, 'w+') as bitmap_file:
		bitmap_response = requests.get(bitmap_url + bitmap_filename)
		bitmap_file.write(bitmap_response.content)

	print('Downloaded %s drawings (category %d/%d)' % 
        (category, index + 1, total_categories))

I guess the problem lies in the way how the file was opened in the first line, where you opened the file as a text file or the other way around the bitmap_response.content has to be converted to a String.
This small code change helped me to let the script working running without any issues:

with open(bitmap_directory + bitmap_filename, 'wb') as bitmap_file: bitmap_response = requests.get(bitmap_url + bitmap_filename) bitmap_file.write(bitmap_response.content)

which open the file in binary mode to accept bytes to write.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions