I'm trying to run a python based print server, based on these instructions, and this code.
I have the print server running on a Raspberry Pi Zero.
I assume the print server is working correctly, as the server gives error messages when I power the printer off, and all looks good when the printer is powered up.
This is how the server looks when it is running:
pi@raspberrypi:~/printserverminimal $ python print_server_minimal.py
* Serving Flask app "print_server_minimal" (lazy loading)
* Environment: production
server starting
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
server ready
connecting printer
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
getting status
printer ready
received notification
7: [ 51 78 A3 01 03 00 00 01 A3 75 FF ]
printer status byte: 00000000
sending to printer
received notification
7: [ 51 78 A3 01 03 00 00 01 A2 72 FF ]
When I send the following curl command, as suggested in the code:
curl --location --request POST 'localhost:5000' --form 'text="hello world"'
I get the following response, but no printout:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>
And the server says:
[2022-07-01 16:29:32,858] ERROR in app: Exception on / [POST]
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib/python3/dist-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/lib/python3/dist-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python3/dist-packages/flask/_compat.py", line 39, in reraise
raise value
File "/usr/lib/python3/dist-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/lib/python3/dist-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/pi/printserverminimal/print_server_minimal.py", line 414, in http_server_upload
text = request.get_json().get("text")
AttributeError: 'NoneType' object has no attribute 'get'
127.0.0.1 - - [01/Jul/2022 16:29:32] "POST / HTTP/1.1" 500 -
getting status
I'm using a Raspberry Pi Zero W Rev 1.1 Raspbian GNU/Linux 11 (bullseye)
I'm trying to print to a Cat Thermal Printer "MINI Printer", which registers its bluetooth name as "MX06"
What is the correct way to send a text print request to this print server, in a way which successfully prints the text on the printer?