Skip to content

Commit 5e72df4

Browse files
committed
Merge pull request #66 from python-fedex-devs/location_v3
Location v3 add location serivce wsdl, base, test and example
2 parents ac1e1d4 + a6b7c5b commit 5e72df4

37 files changed

+2766
-215
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
python-fedex Examples
22
=====================
3+
34
This directory contains a number of examples of how to use python-fedex. For
45
these examples to work, you must open example_config.py and enter your
56
testing account credentials there.
7+
8+
To run all tests from bash, type:
9+
10+
for f in *.py; do python "$f"; done
11+
# Or use the below to only see response errors:
12+
for f in *.py; do python "$f"; done | grep -i error

examples/address_validation.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
class can handle up to 100 addresses for validation.
55
"""
66
import logging
7+
import sys
8+
79
from example_config import CONFIG_OBJ
810
from fedex.services.address_validation_service import FedexAddressValidationRequest
911

1012
# NOTE: TO USE ADDRESS VALIDATION SERVICES, YOU NEED TO REQUEST FEDEX TO ENABLE THIS SERVICE FOR YOUR ACCOUNT.
1113
# BY DEFAULT, THE SERVICE IS DISABLED AND YOU WILL RECEIVE AUTHENTICATION FAILED, 1000 RESPONSE.
1214

13-
# Set this to the INFO level to see the response from Fedex printed in stdout.
14-
logging.basicConfig(level=logging.INFO)
15+
# Un-comment to see the response from Fedex printed in stdout.
16+
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
1517

1618
# This is the object that will be handling our avs request.
1719
# We're using the FedexConfig object from example_config.py in this dir.
@@ -47,7 +49,6 @@ class can handle up to 100 addresses for validation.
4749
address2.Address.CountryCode = 'US'
4850
avs_request.add_address(address2)
4951

50-
5152
# If you'd like to see some documentation on the ship service WSDL, un-comment
5253
# this line. (Spammy).
5354
# print(avs_request.client)
@@ -63,7 +64,16 @@ class can handle up to 100 addresses for validation.
6364
avs_request.send_request()
6465

6566
# good to un-comment to see the variables returned by the Fedex reply.
66-
print(avs_request.response)
67+
# print(avs_request.response)
68+
69+
# This will convert the response to a python dict object. To
70+
# make it easier to work with.
71+
# from fedex.tools.response_tools import basic_sobject_to_dict
72+
# print(basic_sobject_to_dict(avs_request.response))
73+
74+
# This will dump the response data dict to json.
75+
# from fedex.tools.response_tools import sobject_to_json
76+
# print(sobject_to_json(avs_request.response))
6777

6878
# Overall end result of the query
6979
for i in range(len(avs_request.response.AddressResults)):

examples/country_postal_inquiry.py

Lines changed: 0 additions & 57 deletions
This file was deleted.

examples/create_freight_shipment.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
label data that is returned with the reply.
1010
"""
1111
import logging
12+
import sys
1213
import binascii
14+
1315
from example_config import CONFIG_OBJ
1416
from fedex.services.ship_service import FedexProcessShipmentRequest
1517

1618
# What kind of file do you want this example to generate?
1719
# Valid choices for this example are PDF, PNG
1820
GENERATE_IMAGE_TYPE = 'PDF'
1921

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)
2424

2525
# NOTE: A VALID 'freight_account_number' REQUIRED IN YOUR 'CONFIB_OBJ' FOR THIS SERVICE TO WORK.
2626
# OTHERWISE YOU WILL GET FEDEX FREIGHT OR ASSOCIATED ADDRESS IS REQUIRED, ERROR 3619.
@@ -87,7 +87,6 @@
8787
shipment.RequestedShipment.FreightShipmentDetail.Role = role.SHIPPER
8888
shipment.RequestedShipment.FreightShipmentDetail.CollectTermsType = 'STANDARD'
8989

90-
9190
# Specifies the label type to be returned.
9291
shipment.RequestedShipment.LabelSpecification.LabelFormatType = 'FEDEX_FREIGHT_STRAIGHT_BILL_OF_LADING'
9392

@@ -147,7 +146,18 @@
147146
# This will show the reply to your shipment being sent. You can access the
148147
# attributes through the response attribute on the request object. This is
149148
# 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))
151161

152162
# Here is the overall end result of the query.
153163
print("HighestSeverity: {}".format(shipment.response.HighestSeverity))
@@ -160,7 +170,6 @@
160170
amount = shipment.response.CompletedShipmentDetail.ShipmentRating.ShipmentRateDetails[0].TotalNetCharge.Amount
161171
print("Net Shipping Cost (US$): {}".format(amount))
162172

163-
164173
# # Get the label image in ASCII format from the reply. Note the list indices
165174
# we're using. You'll need to adjust or iterate through these if your shipment
166175
# has multiple packages.

examples/create_shipment.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import logging
1111
import binascii
1212
import datetime
13+
import sys
1314

1415
from example_config import CONFIG_OBJ
1516
from fedex.services.ship_service import FedexProcessShipmentRequest
@@ -18,9 +19,8 @@
1819
# Valid choices for this example are PDF, PNG
1920
GENERATE_IMAGE_TYPE = 'PDF'
2021

21-
22-
# Set this to the INFO level to see the response from Fedex printed in stdout.
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)
2424

2525
# This is the object that will be handling our shipment request.
2626
# We're using the FedexConfig object from example_config.py in this dir.
@@ -147,7 +147,18 @@
147147
# This will show the reply to your shipment being sent. You can access the
148148
# attributes through the response attribute on the request object. This is
149149
# good to un-comment to see the variables returned by the Fedex reply.
150-
print(shipment.response)
150+
# print(shipment.response)
151+
152+
# This will convert the response to a python dict object. To
153+
# make it easier to work with. Also see basic_sobject_to_dict, it's faster but lacks options.
154+
# from fedex.tools.response_tools import sobject_to_dict
155+
# response_dict = sobject_to_dict(shipment.response)
156+
# response_dict['CompletedShipmentDetail']['CompletedPackageDetails'][0]['Label']['Parts'][0]['Image'] = ''
157+
# print(response_dict) # Image is empty string for display purposes.
158+
159+
# This will dump the response data dict to json.
160+
# from fedex.tools.response_tools import sobject_to_json
161+
# print(sobject_to_json(shipment.response))
151162

152163
# Here is the overall end result of the query.
153164
print("HighestSeverity: {}".format(shipment.response.HighestSeverity))

examples/delete_shipment.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
This example shows how to delete existing shipments.
44
"""
55
import logging
6+
import sys
7+
68
from example_config import CONFIG_OBJ
79
from fedex.services.ship_service import FedexDeleteShipmentRequest
10+
from fedex.base_service import FedexError
811

9-
# Set this to the INFO level to see the response from Fedex printed in stdout.
10-
logging.basicConfig(level=logging.INFO)
12+
# Un-comment to see the response from Fedex printed in stdout.
13+
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
1114

1215
# This is the object that will be handling our request.
1316
# We're using the FedexConfig object from example_config.py in this dir.
@@ -19,15 +22,33 @@
1922
del_request.DeletionControlType = "DELETE_ALL_PACKAGES"
2023

2124
# The tracking number of the shipment to delete.
22-
del_request.TrackingId.TrackingNumber = '794798682968'
25+
del_request.TrackingId.TrackingNumber = '794798682968' # '111111111111' will also not delete
2326

2427
# What kind of shipment the tracking number used.
2528
# Docs say this isn't required, but the WSDL won't validate without it.
2629
# EXPRESS, GROUND, or USPS
2730
del_request.TrackingId.TrackingIdType = 'EXPRESS'
2831

2932
# Fires off the request, sets the 'response' attribute on the object.
30-
del_request.send_request()
33+
try:
34+
del_request.send_request()
35+
except FedexError as e:
36+
if 'Unable to retrieve record' in str(e):
37+
print "WARNING: Unable to delete the shipment with the provided tracking number."
38+
else:
39+
print(e)
3140

3241
# See the response printed out.
33-
print(del_request.response)
42+
# print(del_request.response)
43+
44+
# This will convert the response to a python dict object. To
45+
# make it easier to work with.
46+
# from fedex.tools.response_tools import basic_sobject_to_dict
47+
# print(basic_sobject_to_dict(del_request.response))
48+
49+
# This will dump the response data dict to json.
50+
# from fedex.tools.response_tools import sobject_to_json
51+
# print(sobject_to_json(del_request.response))
52+
53+
# Here is the overall end result of the query.
54+
print("HighestSeverity: {}".format(del_request.response.HighestSeverity))

examples/example_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66
import os
77
import sys
8+
89
# Use the fedex directory included in the downloaded package instead of
910
# any globally installed versions.
1011
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

examples/freight_rate_request.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
is Out of Delivery Area (ODA).
1010
"""
1111
import logging
12+
import sys
13+
1214
from example_config import CONFIG_OBJ
1315
from fedex.services.rate_service import FedexRateServiceRequest
1416

15-
# Set this to the INFO level to see the response from Fedex printed in stdout.
16-
logging.basicConfig(level=logging.INFO)
17+
# Un-comment to see the response from Fedex printed in stdout.
18+
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
1719

1820
# This is the object that will be handling our request.
1921
# We're using the FedexConfig object from example_config.py in this dir.
@@ -29,7 +31,6 @@
2931

3032
rate_request.RequestedShipment.FreightShipmentDetail.FedExFreightAccountNumber = CONFIG_OBJ.freight_account_number
3133

32-
3334
# Shipper
3435
rate_request.RequestedShipment.Shipper.AccountNumber = CONFIG_OBJ.freight_account_number
3536
rate_request.RequestedShipment.Shipper.Contact.PersonName = 'Sender Name'
@@ -113,17 +114,26 @@
113114
# This will show the reply to your rate_request being sent. You can access the
114115
# attributes through the response attribute on the request object. This is
115116
# good to un-comment to see the variables returned by the FedEx reply.
116-
print(rate_request.response)
117+
# print(rate_request.response)
118+
119+
# This will convert the response to a python dict object. To
120+
# make it easier to work with.
121+
# from fedex.tools.response_tools import basic_sobject_to_dict
122+
# print(basic_sobject_to_dict(rate_request.response))
123+
124+
# This will dump the response data dict to json.
125+
# from fedex.tools.response_tools import sobject_to_json
126+
# print(sobject_to_json(rate_request.response))
117127

118128
# Here is the overall end result of the query.
119-
print("HighestSeverity:", rate_request.response.HighestSeverity)
129+
print("HighestSeverity: {}".format(rate_request.response.HighestSeverity))
120130

121131
# RateReplyDetails can contain rates for multiple ServiceTypes if ServiceType was set to None
122132
for service in rate_request.response.RateReplyDetails:
123133
for detail in service.RatedShipmentDetails:
124134
for surcharge in detail.ShipmentRateDetail.Surcharges:
125135
if surcharge.SurchargeType == 'OUT_OF_DELIVERY_AREA':
126-
print("%s: ODA rate_request charge {}".format(service.ServiceType, surcharge.Amount.Amount))
136+
print("{}: ODA rate_request charge {}".format(service.ServiceType, surcharge.Amount.Amount))
127137

128138
for rate_detail in service.RatedShipmentDetails:
129139
print("{}: Net FedEx Charge {} {}".format(service.ServiceType,

0 commit comments

Comments
 (0)