Closed ionescu77 closed 2 years ago
Can you try explicitly setting the company prefix length?
my_tag = SGTIN.from_sgtin(new_ean, serial_number=serial_number, company_prefix_len=6)
When the length is not specified, the library attempts to guess [1] the company prefix part of the UPC/EAN. This is done using the lookup table from GS1 [2] and is not the most reliable method.
[1] https://github.com/fulfilio/pyepc/blob/4b41debef3a4434117a18b9189af45e5b4f40163/pyepc/epc.py#L576-L579 [2] https://github.com/fulfilio/pyepc/blob/4b41debef3a4434117a18b9189af45e5b4f40163/pyepc/utils.py#L163-L194
@sharoonthomas thank you for the hint.
Indeed using a company_prefix_len
it works. Somehow the company was using some code in the past and now they were using null
which was messing things up!
Possibly the look-up was for 000000
and was returning null also (with the "wrong" EANs like 2100000109869
).
from pyepc import SGTIN
def generate_epc_code(ean, serial_number):
new_ean = '0'+ean
company_prefix_len = len('1111111')
my_tag = SGTIN.from_sgtin(new_ean, serial_number, company_prefix_len)
print(my_tag)
encoded = my_tag.encode()
print(encoded)
Have a great day!
3.6.8
Centos 7.9
Description
Hi, I am trying to encode epc's, however with some EANs it does not work.
What I Did
def generate_epc_code(ean, serial_number): new_ean = '0'+ean my_tag = SGTIN.from_sgtin(new_ean, serial_number=serial_number) encoded = my_tag.encode() return encoded
Error creating EPCs with product 2100000109869. GTIN must be 14 digits
Error creating EPCs with product 2100000109869. GS1 EPC Tag Data Standard only support prefixes between 6 and 12 digits. Got 0 instead