Generating USPS codes with python

The code given in

Seems to be outdated.

  1. The package is not installed with pip install aspose-barcode but pip install asposebarcode

  2. The code is throwing errors:

Traceback (most recent call last):
  File "/Users/amir.giveon/GoogleDrive/pycharmProjects/rect_detect/test.py", line 11, in <module>
    barcodeGeneratorExamples.generateBarcodeImage()
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'BarcodeGeneratorExamples' object has no attribute 'generateBarcodeImage'. Did you mean: 'generateBarcodeImageExample'?

so then, I change to generateBarcodeImageExample and get:

Traceback (most recent call last):
  File "/Users/amir.giveon/GoogleDrive/pycharmProjects/rect_detect/test.py", line 11, in <module>
    barcodeGeneratorExamples.generateBarcodeImageExample()
  File "/Users/amir.giveon/GoogleDrive/pycharmProjects/rect_detect/test.py", line 5, in generateBarcodeImageExample
    generator = Generation.BarcodeGenerator(Generation.EncodeTypes.OneCode, "12345")
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/enum.py", line 784, in __getattr__
    raise AttributeError(name) from None
AttributeError: OneCode

I keep changing things “blindly” and get:

Traceback (most recent call last):
  File "/Users/amir.giveon/GoogleDrive/pycharmProjects/rect_detect/test.py", line 11, in <module>
    barcodeGeneratorExamples.generateBarcodeImageExample()
  File "/Users/amir.giveon/GoogleDrive/pycharmProjects/rect_detect/test.py", line 6, in generateBarcodeImageExample
    generator.getParameters().getBarcode().getCodeTextParameters().setLocation(CodeLocation.Below)
                                                                               ^^^^^^^^^^^^
NameError: name 'CodeLocation' is not defined

Does anyone have a basic working code?

@amir.giveon,

We will look into your issue and get back to you soon.

@amir.giveon,

I found the issue when installing latest version of Aspose.BarCode for Python via Java 24.1 using “pip install aspose-barcode” command. You are right, the pip command and instructions are invalid on the page (Generate USPS OneCode barcode Images via Python via Java | products.aspose.com). The valid pip command can be used from the page(aspose-barcode-for-python-via-java · PyPI) but it has other issues.

The code on the page (Generate USPS OneCode barcode Images via Python via Java | products.aspose.com) is not standalone and is using/referring to the Github examples (https://github.com/aspose-barcode/Aspose.BarCode-for-Python-via-Java/tree/master/src/examples).

We have logged a ticket with an id “BARCODEJAVA-1776” for all these issues. We will look into and figure out the issues soon. Once we figure out issue(s) or we have some other updates, we will let you know here.