Shippo - Python包异步问题

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (20)

我已经导入了Shippo python包,我试图让他们的样本工作,但我遇到了以下错误消息(见下文)。我在最新的API版本上运行Python 3.7.2。

这是错误 -

    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

这是代码 -

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"
)
提问于
用户回答回答于

该软件包的Python版本覆盖率高达3.3。在3.6+版本中,“async”成为保留关键字,导致您获得语法错误。

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

扫码关注云+社区

领取腾讯云代金券