Fix bugs in the Python code about Brother Label Printer.

Job ID: 37137120

Budget: $10 – $30 USD

Fix bugs in the Python code.

I want to print labels using the library "brother_ql".

Here is the coat that is currently ready.

There is an error on pyusb in btother_ql.

The error is "NoBackendError" where the backend object cannot be found.

'''#CURRENT CODE
from usb.core import NoBackendError
import brother_ql
from brother_ql.backends import backend_factory

class Brother:

def __init__(self) -> None:
'''Initialize'''

def printout(self, image: Image) -> None:
'''プリント'''
identifier = 'usb://0x04f9:0x209b'
model = 'QL-800'
printer = brother_ql.BrotherQLRaster(model)

backend_dict = backend_factory('pyusb')
backend_class = backend_dict .get('backend_class')
list_available_devices = backend_dict .get('list_available_devices')
try:
identifiers = list_available_devices()
identifier = identifiers[0]['identifier']
except NoBackendError:
print('No USB devices detected.')
return
backend = backend_class(identifier)
instructions = brother_ql.create_label(
qlr=printer,
image=image,
label_size='62',
threshold=70,
cut=True,
dither=False,
compress=False,
red=False
)
backend.write(instructions[0])
backend.close()
'''


The backend cannot be confirmed by setting "libsub-1.0.dll" directly in the following test code.
I can also connect a QL-800 printer to USB and print a test print, but it is not recognized by Python.

Please contact us only if you can solve this issue with the results.

Thank you in advance.


'''#TEST CODE
import usb.core
import usb.backend.libusb1

try:
backend = usb.backend.libusb1.get_backend(find_library=lambda x: r".\libusb-1.0.dll")
if backend is None:
print("Not found backend.")
exit(1)
dev = usb.core.find(backend=backend)
if dev is None:
print("Not found device.")
exit(1)
print(f"Device: {dev}")
print(f"Backend: {backend}")
except Exception as e:
print(f"error occurs{e}")

'''