代码之家  ›  专栏  ›  技术社区  ›  mfcss

如何在python-fedex中为国际货运增加关税?

  •  0
  • mfcss  · 技术社区  · 6 年前

    我用的是 python-fedex

    fedex.base_service.FedexError: Customs Value is required. (Error code: 2033)

    this link 有了一些指导(来自C#),但我无法让它在Python中运行。感谢您的任何意见!

    我的代码如下:


    # !/usr/bin/env python
    """
    This example shows how to create a shipment and generate a waybill as output. The variables populated below
    represents the minimum required values. You will need to fill all of these, or
    risk seeing a SchemaValidationError exception thrown.
    
    Near the bottom of the module, you'll see some different ways to handle the
    label data that is returned with the reply.
    """
    
    import logging
    import binascii
    import datetime
    import sys, os
    
    from example_config import CONFIG_OBJ
    
    from fedex.services.ship_service import FedexProcessShipmentRequest
    
    
    # What kind of file do you want this example to generate?
    # Valid choices for this example are PDF, PNG
    GENERATE_IMAGE_TYPE = 'PDF'
    
    # Un-comment to see the response from Fedex printed in stdout.
    logging.basicConfig(stream=sys.stdout, level=logging.INFO)
    
    # This is the object that will be handling our shipment request.
    # We're using the FedexConfig object from example_config.py in this dir.
    customer_transaction_id = "*** ShipService Request v17 using Python ***"  # Optional transaction_id
    shipment = FedexProcessShipmentRequest(CONFIG_OBJ, customer_transaction_id=customer_transaction_id)
    
    # This is very generalized, top-level information.
    # REGULAR_PICKUP, REQUEST_COURIER, DROP_BOX, BUSINESS_SERVICE_CENTER or STATION
    shipment.RequestedShipment.DropoffType = 'BUSINESS_SERVICE_CENTER'
    
    # See page 355 in WS_ShipService.pdf for a full list. Here are the common ones:
    # STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, FEDEX_EXPRESS_SAVER,
    # FEDEX_2_DAY, INTERNATIONAL_PRIORITY, SAME_DAY, INTERNATIONAL_ECONOMY
    shipment.RequestedShipment.ServiceType = 'INTERNATIONAL_PRIORITY'
    
    # What kind of package this will be shipped in.
    # FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, FEDEX_ENVELOPE
    shipment.RequestedShipment.PackagingType = 'FEDEX_ENVELOPE'
    
    # Shipper contact info.
    shipment.RequestedShipment.Shipper.Contact.PersonName = 'Shipper Name'
    shipment.RequestedShipment.Shipper.Contact.CompanyName = 'Shipper Company'
    shipment.RequestedShipment.Shipper.Contact.PhoneNumber = '004512345678'
    
    # Shipper address.
    shipment.RequestedShipment.Shipper.Address.StreetLines = ['Shipper Address']
    shipment.RequestedShipment.Shipper.Address.City = 'City'
    shipment.RequestedShipment.Shipper.Address.StateOrProvinceCode = ''
    shipment.RequestedShipment.Shipper.Address.PostalCode = '8270'
    shipment.RequestedShipment.Shipper.Address.CountryCode = 'DK'
    shipment.RequestedShipment.Shipper.Address.Residential = False
    
    # Recipient contact info.
    shipment.RequestedShipment.Recipient.Contact.PersonName = 'US customer X'
    shipment.RequestedShipment.Recipient.Contact.CompanyName = 'US company X'
    shipment.RequestedShipment.Recipient.Contact.PhoneNumber = '0123456789'
    
    # Recipient address
    shipment.RequestedShipment.Recipient.Address.StreetLines = ['668 MURRAY AVE SE']
    shipment.RequestedShipment.Recipient.Address.City = 'ROANOKE'
    shipment.RequestedShipment.Recipient.Address.StateOrProvinceCode = 'VA'
    shipment.RequestedShipment.Recipient.Address.PostalCode = '24013'
    shipment.RequestedShipment.Recipient.Address.CountryCode = 'US'
    # This is needed to ensure an accurate rate quote with the response. Use AddressValidation to get ResidentialStatus
    shipment.RequestedShipment.Recipient.Address.Residential = False
    shipment.RequestedShipment.EdtRequestType = 'NONE'
    
    # Senders account information
    shipment.RequestedShipment.ShippingChargesPayment.Payor.ResponsibleParty.AccountNumber = CONFIG_OBJ.account_number
    
    # Who pays for the shipment?
    # RECIPIENT, SENDER or THIRD_PARTY
    shipment.RequestedShipment.ShippingChargesPayment.PaymentType = 'SENDER'
    
    # Specifies the label type to be returned.
    # LABEL_DATA_ONLY or COMMON2D
    shipment.RequestedShipment.LabelSpecification.LabelFormatType = 'COMMON2D'
    
    # Specifies which format the label file will be sent to you in.
    # DPL, EPL2, PDF, PNG, ZPLII
    shipment.RequestedShipment.LabelSpecification.ImageType = GENERATE_IMAGE_TYPE
    
    # To use doctab stocks, you must change ImageType above to one of the
    # label printer formats (ZPLII, EPL2, DPL).
    # See documentation for paper types, there quite a few.
    shipment.RequestedShipment.LabelSpecification.LabelStockType = 'PAPER_7X4.75'
    
    # This indicates if the top or bottom of the label comes out of the
    # printer first.
    # BOTTOM_EDGE_OF_TEXT_FIRST or TOP_EDGE_OF_TEXT_FIRST
    # Timestamp in YYYY-MM-DDThh:mm:ss format, e.g. 2002-05-30T09:00:00
    shipment.RequestedShipment.ShipTimestamp = datetime.datetime.now().replace(microsecond=0).isoformat()
    
    # BOTTOM_EDGE_OF_TEXT_FIRST, TOP_EDGE_OF_TEXT_FIRST
    shipment.RequestedShipment.LabelSpecification.LabelPrintingOrientation = 'TOP_EDGE_OF_TEXT_FIRST'
    
    # Delete the flags we don't want.
    # Can be SHIPPING_LABEL_FIRST, SHIPPING_LABEL_LAST or delete
    if hasattr(shipment.RequestedShipment.LabelSpecification, 'LabelOrder'):
        del shipment.RequestedShipment.LabelSpecification.LabelOrder  # Delete, not using.
    
    # Create Weight, in pounds.
    package1_weight = shipment.create_wsdl_object_of_type('Weight')
    package1_weight.Value = 1.0
    package1_weight.Units = "LB"
    
    # Create PackageLineItem
    package1 = shipment.create_wsdl_object_of_type('RequestedPackageLineItem')
    # BAG, BARREL, BASKET, BOX, BUCKET, BUNDLE, CARTON, CASE, CONTAINER, ENVELOPE etc..
    package1.PhysicalPackaging = 'ENVELOPE'
    package1.Weight = package1_weight
    
    
    # Add a signature option for the package using SpecialServicesRequested or comment out.
    # SpecialServiceTypes can be APPOINTMENT_DELIVERY, COD, DANGEROUS_GOODS, DRY_ICE, SIGNATURE_OPTION etc..
    package1.SpecialServicesRequested.SpecialServiceTypes = 'SIGNATURE_OPTION'
    # SignatureOptionType can be ADULT, DIRECT, INDIRECT, NO_SIGNATURE_REQUIRED, SERVICE_DEFAULT
    package1.SpecialServicesRequested.SignatureOptionDetail.OptionType = 'SERVICE_DEFAULT'
    
    
    # This adds the RequestedPackageLineItem WSDL object to the shipment. It
    # increments the package count and total weight of the shipment for you.
    shipment.add_package(package1)
    
    
    # If you want to make sure that all of your entered details are valid, you
    # can call this and parse it just like you would via send_request(). If
    # shipment.response.HighestSeverity == "SUCCESS", your shipment is valid.
    # print(shipment.send_validation_request())
    
    # Fires off the request, sets the 'response' attribute on the object.
    shipment.send_request()
    
    0 回复  |  直到 6 年前
        1
  •  1
  •   jc l    6 年前

    你需要添加更多信息。

    在前面插入以下代码 shipment.send_request() ,然后重试。

    shipment.RequestedShipment.CustomsClearanceDetail.CustomsValue.Currency = 'USD'
    shipment.RequestedShipment.CustomsClearanceDetail.CustomsValue.Amount = 1.0
    shipment.RequestedShipment.CustomsClearanceDetail.DutiesPayment.PaymentType = 'SENDER'
    shipment.RequestedShipment.CustomsClearanceDetail.DutiesPayment.Payor.ResponsibleParty.AccountNumber = CONFIG_OBJ.account_number
    
    commodity1 = shipment.create_wsdl_object_of_type('Commodity')
    commodity1.Name = 'book'
    commodity1.NumberOfPieces = 1
    commodity1.Description = '1'
    commodity1.CountryOfManufacture = 'CN'
    commodity1.HarmonizedCode = '123456789'
    
    commodity1.Quantity = 1.0
    commodity1.QuantityUnits = 'EA'
    
    commodity1.Weight.Value = 1.0
    commodity1.Weight.Units = "LB"
    
    commodity1.CustomsValue.Currency = 'USD'
    commodity1.CustomsValue.Amount = 1.0
    
    commodity1.UnitPrice.Currency = 'USD'
    commodity1.UnitPrice.Amount = 1.0
    
    shipment.RequestedShipment.CustomsClearanceDetail.Commodities = [commodity1]