簡體   English   中英

Shippo - Python 包異步問題

[英]Shippo - Python Package Async Issue

我已經導入了 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”參數顯式更改為“asynchronous”。 這至少應該避免語法錯誤,直到包更新為 3.6+ 支持。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM