pklaus / brother_ql_web

A Python-based web service to print labels on Brother QL label printers. Based on brother_ql: https://github.com/pklaus/brother_ql
GNU General Public License v3.0
254 stars 124 forks source link

invalid literal for int() with base 16: 'Brother' on Mac OS X #10

Closed timmerk closed 4 years ago

timmerk commented 6 years ago

I'm trying to use this app with a Brother QL-700 connected through an ethernet Silex USB server. This might be the problem, but maybe not. Other OS X apps can communicate with the QL-700 fine, and System Profiler shows the address of the QL-700 to be "usb://Brother/QL-700?serial=000F2Z67XXXX" (replaced numbers with Xs), which I entered in the configuration file. However, when I try to print, I get:

invalid literal for int() with base 16: 'Brother'

which I assume is the "Brother" in the USB device address. The problem appears to be in the pyusb backend in the brother_ql project. It's expecting a USB vendor and product ID, and not a name that can occur in OS X. However, I might be out of luck, because when I list all devices using pyusb, the Brother doesn't appear there.

Any suggestions? Perhaps I will need to make another backend for this pseudo USB connection.

logazer commented 5 years ago

I ran into the exact same error message, which brought me here. I'm using Ubuntu and I have the same address scheme for my printer: (usb://Brother/QL-800?serial=000H8ZXXXXXX)

In my case however, I looked up the vendor and product ID via lsusb: Bus 001 Device 016: ID 04f9:XXXX Brother Industries, Ltd and edited the config.json like so:

"PRINTER": {
    "MODEL": "QL-800",
    "PRINTER": "usb://0x04f9:0xXXXX/000H8ZXXXXXX"
  },

After this, it printed without problems. So solved for me. But I was curious and checked directly via pyusb. I was able to find my printer using the following:

# python3
import usb.core
dev = usb.core.find(find_all=True)
for d in dev:
   print(d)

Here it was listed. But maybe my solution workaround works for you as well. Let me know!

ghost commented 4 years ago

@LoGazer are you able to print with QL-800 normally from Ubuntu?

logazer commented 4 years ago

@kennedybaird Do you mean outside of the software in this repository? I have no problems. Just choose the printer in the dialog in LibreOffice for example. Works as expected :)

ghost commented 4 years ago

@LoGazer Yes. Using LibreOffice or any application I get the blinking red LED.

Only way I've managed to get it to print is using the CLI with brother_ql adding the --red tag.

logazer commented 4 years ago

@kennedybaird Mmh, on my device I've never seen a LED blinking red I believe, you could check with the manual in the section "LED Indications".

But: If the left LED right over the button labeled Editor Lite is lit up (green in my case), the printer won't print either. If I remember correctly, this mode is what you need if you want to use the special software (only for Mac / Windows). But for normal printing in Linux, you should longpress to deactivate the mode (LED off). I did think of it, because you mentioned the --red tag and red printing normally only works in the special software, which is what this repository solves for linux.

pklaus commented 4 years ago

Thanks for reporting and sorry for being slow in responding. So let's separate the issues here:

The original issue was about the format usb://Brother/QL-700?serial=000F2Z67XXXX not being supported by brother_ql / brother_ql_web. Yes, it was never made for this format, although I like it. I might implement that format at some point as it's much nicer to read. I took a note to add this in the brother_ql pyusb backend. Currently, the only supported format is: usb://0xdead:0xbeef/000H8ZXXXXXX where 0xdead stands for the USB device's Vendor ID and 0xbeef stands for the device's Product ID. The code behind the slash is the serial number of the device.

What concerns the QL-800 issues: those problems were addressed in 2b5902a and 6da0745. See also issue #7.

pklaus commented 4 years ago

BTW: you can try to get a list of available printers (and their identifiers) via:

brother_ql --backend pyusb discover
miqmago commented 2 years ago

In a OSX the returned value cannot be used as it produces the same error:

brother_ql --backend pyusb discover
usb://0xdeead:0xbeef_Љ

ValueError: invalid literal for int() with base 16: '0xbeef_Љ'

The problem is in pyusb.py:

serial = usb.util.get_string(dev, 256, dev.iSerialNumber)

I'v looked the idSerialNumber E78252F0NXXXXXX manually by printing print(dev), and it works fine then.

Also to mention that the output in pyusb is not correct, it has an underscore instead a slash:

return 'usb://0x{:04x}:0x{:04x}_{}'.format(dev.idVendor, dev.idProduct, serial)