|
9 | 9 | label data that is returned with the reply. |
10 | 10 | """ |
11 | 11 | import logging |
| 12 | +import sys |
12 | 13 | import binascii |
| 14 | + |
13 | 15 | from example_config import CONFIG_OBJ |
14 | 16 | from fedex.services.ship_service import FedexProcessShipmentRequest |
15 | 17 |
|
16 | 18 | # What kind of file do you want this example to generate? |
17 | 19 | # Valid choices for this example are PDF, PNG |
18 | 20 | GENERATE_IMAGE_TYPE = 'PDF' |
19 | 21 |
|
20 | | - |
21 | | -# Set this to the INFO level to see the response from Fedex printed in stdout. |
22 | | -# logging.basicConfig(filename="suds.log", level=logging.DEBUG) |
23 | | -logging.basicConfig(level=logging.INFO) |
| 22 | +# Un-comment to see the response from Fedex printed in stdout. |
| 23 | +logging.basicConfig(stream=sys.stdout, level=logging.INFO) |
24 | 24 |
|
25 | 25 | # NOTE: A VALID 'freight_account_number' REQUIRED IN YOUR 'CONFIB_OBJ' FOR THIS SERVICE TO WORK. |
26 | 26 | # OTHERWISE YOU WILL GET FEDEX FREIGHT OR ASSOCIATED ADDRESS IS REQUIRED, ERROR 3619. |
|
87 | 87 | shipment.RequestedShipment.FreightShipmentDetail.Role = role.SHIPPER |
88 | 88 | shipment.RequestedShipment.FreightShipmentDetail.CollectTermsType = 'STANDARD' |
89 | 89 |
|
90 | | - |
91 | 90 | # Specifies the label type to be returned. |
92 | 91 | shipment.RequestedShipment.LabelSpecification.LabelFormatType = 'FEDEX_FREIGHT_STRAIGHT_BILL_OF_LADING' |
93 | 92 |
|
|
147 | 146 | # This will show the reply to your shipment being sent. You can access the |
148 | 147 | # attributes through the response attribute on the request object. This is |
149 | 148 | # good to un-comment to see the variables returned by the Fedex reply. |
150 | | -print(shipment.response) |
| 149 | +# print(shipment.response) |
| 150 | + |
| 151 | +# This will convert the response to a python dict object. To |
| 152 | +# make it easier to work with. Also see basic_sobject_to_dict, it's faster but lacks options. |
| 153 | +# from fedex.tools.response_tools import sobject_to_dict |
| 154 | +# response_dict = sobject_to_dict(shipment.response) |
| 155 | +# response_dict['CompletedShipmentDetail']['ShipmentDocuments'][0]['Parts'][0]['Image'] = '' |
| 156 | +# print(response_dict) # Image is empty string for display purposes. |
| 157 | + |
| 158 | +# This will dump the response data dict to json. |
| 159 | +# from fedex.tools.response_tools import sobject_to_json |
| 160 | +# print(sobject_to_json(shipment.response)) |
151 | 161 |
|
152 | 162 | # Here is the overall end result of the query. |
153 | 163 | print("HighestSeverity: {}".format(shipment.response.HighestSeverity)) |
|
160 | 170 | amount = shipment.response.CompletedShipmentDetail.ShipmentRating.ShipmentRateDetails[0].TotalNetCharge.Amount |
161 | 171 | print("Net Shipping Cost (US$): {}".format(amount)) |
162 | 172 |
|
163 | | - |
164 | 173 | # # Get the label image in ASCII format from the reply. Note the list indices |
165 | 174 | # we're using. You'll need to adjust or iterate through these if your shipment |
166 | 175 | # has multiple packages. |
|
0 commit comments