-3

An application is being developed to control a thermal printer. The script to control the thermal printer is being executed from a Docker container.

This printer is attached to a USB port of a Raspberry Pi 4. The programming language is Python. There is an error at the time of configuration of the printer, that needs to be resolved. The following are scripts of Dockerfile, Requirements and the Error:

Dockerfile:

FROM python:3.8.3-alpine

# set work directory
WORKDIR /usr/src/app

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install psycopg2 dependencies
RUN apk update \
    && apk add postgresql-dev gcc python3-dev musl-dev 
RUN apk add libjpeg-turbo-dev freetype-dev libpng-dev libusb 
RUN apk add --update --no-cache curl jq py3-configobj py3-pip py3-setuptools python3 python3-dev

# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install -r requirements.txt

# copy entrypoint.sh
COPY ./entrypoint.sh .

# copy project
COPY . .

# run entrypoint.sh
ENTRYPOINT ["/usr/src/app/entrypoint.sh"]

Requirements:

    Django==3.0.7
python-escpos==2.2.0
gunicorn==20.0.4
requests==2.24.0
psycopg2==2.8.5
psycopg2-binary==2.8.5
djangorestframework==3.11.0
django-cors-headers==3.4.0
pyusb==1.1.0
libusb1==1.9.1
libusb==1.0.23b7
pytz
escpos==1.8

Error:

    Warning: missing lib... win32print
print paper
Traceback (most recent call last):
  File "services/receipt_content.py", line 123, in <module>
    a = ReceiptHeader("165465481654654", "app/media/loto.png", None)
  File "services/receipt_content.py", line 29, in _init_
    PrintPaper._init_(self)
  File "services/receipt_content.py", line 10, in _init_
    self.printer = Usb(0x0fef, 0x811e, 98, 0x82, 0x02)
  File "/usr/local/lib/python3.8/site-packages/escpos/printer.py", line 50, in _init_
    usb_args['idVendor'] = idVendor
TypeError: 'int' object does not support item assignment
user3736295
  • 150
  • 3
  • 9
  • [Don't paste images of code or error messages](https://meta.stackoverflow.com/q/303812/13860) – Jonathan Hall Dec 16 '20 at 15:06
  • Please post code, errors, sample data or textual output here as plain-text, not as images that can be hard to read, can’t be copy-pasted to help test code or use in answers, and are barrier to those who depend on screen readers or translation tools. You can edit your question to add the code in the body of your question. For easy formatting use the `{}` button to mark blocks of code, or indent with four spaces for the same effect. The contents of a **screenshot can’t be searched, run as code, or copied and edited to create a solution.** – tadman Dec 16 '20 at 15:06
  • Done! The content was edited to include the text that can run as code, copied and edited to create a solution. – user3736295 Dec 16 '20 at 15:38

1 Answers1

0

Looks like this is a problem either within the escpos library — or with your usage of that library.

In particular, you don't show the relevant code, but the traceback quotes part of it:

    self.printer = Usb(0x0fef, 0x811e, 98, 0x82, 0x02)

It's hard to tell for sure what's going on here, due to the abundant magic constants... but I'd make a reasonable guess that 0x82 is supposed to stand for in_ep and 0x02 for out_ep.

You should follow the docs of the library you're using:

__init__(idVendor, idProduct, usb_args=None, timeout=0, in_ep=130, out_ep=1, *args, **kwargs)

E.g. notice the misalignment of arguments 4 and 5.

On a code review, I'd strongly question the 98 constant, too.

ulidtko
  • 14,740
  • 10
  • 56
  • 88