33This example shows how to ship shipments.
44"""
55import logging
6+ import binascii
67from fedex .services .ship_service import FedexProcessShipmentRequest
78from fedex .config import FedexConfig
89
9899# This will show the reply to your shipment being sent. You can access the
99100# attributes through the response attribute on the request object.
100101print ship .response
102+
103+ # Get the label image in ASCII format from the reply.
104+ ascii_label_data = ship .response .CompletedShipmentDetail .CompletedPackageDetails [0 ].Label .Parts [0 ].Image
105+ # Convert the ASCII data to binary.
106+ label_binary_data = binascii .a2b_base64 (ascii_label_data )
107+ # This will be the file we write the label out to.
108+ png_file = open ('example_shipment_label.png' , 'wb' )
109+
110+ """
111+ This is an example of how to dump a label to a PNG file.
112+ """
113+ png_file .write (label_binary_data )
114+ png_file .close ()
115+
116+ """
117+ This is an example of how to print the label to a serial printer. This will not
118+ work for all label printers, consult your printer's documentation for more
119+ details on what formats it can accept.
120+ """
121+ # Pipe the binary directly to the label printer. Works under Linux
122+ # without requiring PySerial. This WILL NOT work on other platforms.
123+ #label_printer = open("/dev/ttyS0", "w")
124+ #label_printer.write(label_binary_data)
125+ #label_printer.close()
126+
127+ """
128+ This is a potential cross-platform solution using pySerial. This has not been
129+ tested in a long time and may or may not work. For Windows, Mac, and other
130+ platforms, you may want to go this route.
131+ """
132+ #import serial
133+ #label_printer = serial.Serial(0)
134+ #print "SELECTED SERIAL PORT: "+ label_printer.portstr
135+ #label_printer.write(label_binary_data)
136+ #label_printer.close()
0 commit comments