Giter Site home page Giter Site logo

python-ship's Introduction

This is my extremely early version of providing a shipment API in Python.

UPS: Ground shipping almost complete USPS: Rate query complete, delivery confirmation almost complete FedEx: Not implemented

ups_config and fedex_config dictionaries:

  fedex_config = {
    'meter_number': 'FedEx Meter Number', 
    'password': 'FedEx API password', 
    'account_number': 'FedEx Account Number', 
    'key': 'FedEx API Key'
  }
     
  ups_config = {
    'username': 'UPS Online Username',
    'password': 'UPS Online Password', 
    'shipper_number': 'UPS Shipper Number',
    'access_license': 'UPS API License'
  }

USPS Domestic Shipping Rate Example

The USPS module uses Endicia to calculate shipping rates and generate labels. For this example, we'll need to import the Package and Endicia classes from the endicia module and the Address class from the shipping module:

from endicia import Package, Endicia
from shipping import Address

To calculate shipping or generate a label, you have to first create a Package object:

# Separate variables for the sake of clarity.
mail_class = Package.shipment_types[0] # "Priority"
weight_in_oz = 20
packaging_shape = Package.shapes[1] # "MediumFlatRateBox"
length = 10 # inches
width = 10 # inches
height = 10 # inches

package = Package(mail_class, weight_in_oz, packaging_shape, length, width, height)

You also need to create Address objects to represent the address you are shipping from and the address you are shipping to:

shipper = Address('Microsoft', "1 157th Ave NE", 'Redmond', 'WA', 98052, 'US')
recipient = Address("Apple", "1 Infinite Loop", 'Cupertino', 'CA', 95014, 'US')

And finally, you need to create an Endicia object and pass your authentication info, package, and addresses to it:

api = Endicia({
    "partner_id": "<your partner ID goes here>",
    "account_id": "000000", # Your account ID. Has to be a six-digit value.
    "passphrase": "<your passphrase goes here>"
})

Then you are free to call whatever API functions on the Endicia object you like. In this example, we want the rate function:

shipping_rate = api.rate([package], package.shape, shipper, recipient, debug=True) 

Which should put something like this in shipping_rate:

{
    'status': 0,
    'info': [
        {
            'delivery_day': '', 
            'cost': 11.3, 
            'service': Priority Mail Medium Flat Rate Box,
            'package': Priority
        },
        {
            'delivery_day': '',
            'cost': 39.95,
            'service': Priority Mail Express Flat Rate Box,
            'package': Express
        }
    ]
}

python-ship's People

Contributors

benweatherman avatar htristan avatar r3dfish avatar tedshroyer avatar winkervsbecks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-ship's Issues

Rate Request Namespace

I'm working on getting the rate() working with UPS, I sent the request that gets generated over to the UPS tech support, they responded saying the namespace was incorrect, I'm not sure how the namespaces get defined/assigned.

Here is the relevant part of the request to rate() :

ns2:Body
ns1:RateRequest
ns1:Request
ns0:RequestOptionShop/ns0:RequestOption
/ns1:Request
ns1:CustomerClassification

The UPS Tech Support responded saying that it should look like this:

ns1:RateRequest
ns0:Request
ns0:RequestOptionShop/ns0:RequestOption
/ns0:Request

With the explaination:
The cause of your error is an invalid namespace association for the /RateRequest/Request container. This is causing the API to ignore any data within the container.

The entire container is considered a Common element rather than specific to the Rating API. As such, the name space assignment should be as follows:

How do we go about getting the Request container to be ns0 instead of ns1?

test.py

Hi,

I ran into a few little bugs while trying to run test.py. Please see the following:

Line 55 in test.py:
response = u.label(intl_packages, shipper, r, ups.SERVICES[9][0], ups.PACKAGES[5][0], validate, [ '[email protected] '], create_commercial_invoice=True, products=products)

products=products should be replaced by customs_info=products in order to match the following:
def label(self, packages, shipper_address, recipient_address, service, box_shape, validate_address, email_notifications=list(), create_commercial_invoice=False, customs_info=[])


Line 45 and 46 in test.py:
P(total=10, item_price=2, quantity=5, description='It\'s just a bunch of widgets')

ups.py requests for p.value and p.country both of which are missing in the above declaration. The following fixes this issue:
P(total=10, value=2, quantity=5, description='It\'s just a bunch of widgets', country = 'CA')

UPS Error 120051

I'm not sure what is causing this one. The config has been populated with brand new UPS account/pass/key. Running ups tests produces:

UPS Error 120051: SurePost shipments for this UPS account can only be delivered to a PO Box/APO/FPO/DPO.

Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.