Exemple #1
0
def FedExShip(
    toState="CO",
    toZip="80501",
    fromState="TN",
    fromZip="37932",
    toCountry="United States",
    packages=[6.0001, 2.3],
    weight=10.0,
):
    ship = shipping.create(
        "FedEx",
        "AvailableRates",
        {"account_number": "361927826", "meter_number": "7340835"},  # a 9 digit number
        from_state=fromState,
        from_zip_code=fromZip,
        to_state=toState,
        to_zip_code=toZip,
        to_country=toCountry,
        # The following args have defaults but they're left here for example
        # on how to change them, should the need arise.
        # service = 'GROUNDHOMEDELIVERY',
        # service='FEDEXGROUND',
        # packaging = 'FEDEXBOX',
        # weight_units = 'LBS',
        weight=weight,
    )
    # addPackage can accept lists of weights for multiple packages or single floats
    ship.addPackage(packages)
    shipInfo = None
    try:
        print ship
        print
        print dir(ship)
        print
        shipInfo = ship.getResponse(returnAllResults=True)
        print shipInfo
    except (shipping.NoResultsError, shipping.OnlineToolError), error_text:
        print ship.responsexml.toprettyxml()
        print error_text
        print
Exemple #2
0
def UPSShip(toZip="80501", fromZip="37932", toCountry="United States", packages=[6, 2.3]):
    """Examples:
	UPSShip('80501') # Some random place in Colorado
	UPSShip('00785','PR') # Some random place in Puerto Rico
	UPSShip('09096','United States',[7.5,10,2.3]) # Some random place in Hawaii (or... Alaska. I forget.)
	"""
    ship = shipping.create(
        "UPS",
        "SimpleRate",
        {"accesskey": "BBFF633F986ECB79", "userid": "david_abrahams", "password": "******"},  # a 16-character string
        from_zip_code=fromZip,
        to_zip_code=toZip,
        to_country=toCountry,
    )
    ship.addPackage(packages)
    shipInfo = None
    try:
        shipInfo = ship.getResponse(returnAllResults=True)
        print shipInfo
    except (shipping.NoResultsError, shipping.OnlineToolError), error_text:
        print ship.responsexml.toprettyxml()
        print error_text
        print