zeep.exceptions.Fault - Invalid Enum Value | Python Zeep Enum Attribute Error

Viewed 120
def generate_waybill(shipper, consignee, services, profile):
    success = True

    request = {
        "Shipper": shipper,
        "Consignee": consignee,
        "Services": services
    }

    client = Client(url)
    
    res = client.service.GenerateWayBill(Request=request, Profile=profile)
    
    print("RESPONSE GENERATE WAYBILL: \n\n", res, res.json())

    if not res:
        success = False

    return res, success

While calling the generate_waybill function i get an execption from zeep >>> 'Invalid enum value 'ProductType.Dutiables'

In the services object it has a key named as ProductType and its Data Type ProductType [Enumerator] and the allowed values for this fields are ProductType.Docs, ProductType.Dutiables.

The services object

services = {
    "ProductCode": shipping_options['bluedart']['product_code'],
    "ProductType": shipping_options['bluedart']['product_type'],
    "PieceCount": return_request_line_items.all().count(),
    "ActualWeight": weight,
    "CreditReferenceNo": reference_id,
    "PickupDate": timezone.now() + timezone.timedelta(days=2),
    "PickupTime": '1052',
    "RegisterPickup": True,
    "IsReversePickup": True
}

In the "ProductType": field I have passed hard coded string value as 'ProductType.Dutiables'

I have also tried creating a calss with Enum type like

from enum import Enum
class ProductType(Enum):
    Dutiables = "Dutiables"

and used this as ProductType.Dutiables in the 'ProductType' field.

But nothing seems to work for me. Please help!

zeep.exceptions.Fault: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:Request. The InnerException message was 'Invalid enum value 'ProductType.Dutiables' cannot be deserialized into type 'SAPI.Entities.Enums.AWBGeneration.ProductType'. Ensure that the necessary enum values are present and are marked with EnumMemberAttribute attribute if the type has DataContractAttribute attribute.'.  Please see InnerException for more details.
0 Answers
Related