2

I have imported the Shippo python package and I am trying to get their sample to work but I am running into the following error message (see below). I am running Python 3.7.2 on the most current API version.

Here is the error -

    Traceback (most recent call last):
      File "c:/Users/tom/Documents/PyProjects/goShippo/goShippoCreateLabels.py", line 1, in <module>
        import shippo
      File "C:\Python\lib\site-packages\shippo\__init__.py", line 8, in <module>
        from shippo.resource import (
      File "C:\Python\lib\site-packages\shippo\resource.py", line 303
        def get_rates(cls, object_id, async=False, api_key=None, currency=None, **params):
                                      ^
SyntaxError: invalid syntax

Here is the code -

import shippo

shippo.api_key = "shippo_test_123456789"

address_from = {
    "name": "Shawn Ippotle",
    "company": "Shippo",
    "street1": "215 Clayton St.",
    "city": "San Francisco",
    "state": "CA",
    "zip": "94117",
    "country": "US",
    "phone": "+1 555 341 9393",
    "email": "shippotle@goshippo.com"
}

address_to = {
    "name": "Mr Hippo",
    "company": "",
    "street1": "Broadway 1",
    "street2": "",
    "city": "New York",
    "state": "NY",
    "zip": "10007",
    "country": "US",
    "phone": "+1 555 341 9393",
    "email": "mrhippo@goshippo.com",
    "metadata": "Hippos dont lie"
}

parcel = {
    "length": "5",
    "width": "5",
    "height": "5",
    "distance_unit": "in",
    "weight": "2",
    "mass_unit": "lb"
}

shipment = {
    "address_from": address_from,
    "address_to": address_to,
    "parcels": [parcel]
}

transaction = shippo.Transaction.create(
    shipment = shipment,
    carrier_account = "b741b99f95e841639b54272834bc478c",
    servicelevel_token = "usps_priority"
)
4

1 回答 1

3

这个包的 Python 版本覆盖率高达 3.3。在 3.6+ 版本中,“async”成为保留关键字,导致您遇到语法错误。

由于“async”是默认参数,最好的解决方法是将“async”参数显式更改为“asynchronous”。这至少应该避免语法错误,直到软件包更新为 3.6+ 支持。

于 2019-03-14T22:37:50.873 回答