Shippo - Python 包异步问题
Posted
技术标签:
【中文标题】Shippo - Python 包异步问题【英文标题】:Shippo - Python Package Async Issue 【发布时间】:2019-03-14 19:41:35 【问题描述】:我已经导入了 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"
)
【问题讨论】:
【参考方案1】:此包的 Python 版本覆盖率最高为 3.3。在 3.6+ 版本中,“async”成为保留关键字,导致您遇到语法错误。
由于“async”是默认参数,最好的解决方法是将“async”参数显式更改为“asynchronous”。这至少应该避免语法错误,直到软件包更新为 3.6+ 支持。
【讨论】:
以上是关于Shippo - Python 包异步问题的主要内容,如果未能解决你的问题,请参考以下文章
如何在不使 main() 异步的情况下将异步对象注册到 get_it 包?
scrapy 爬取知乎问题答案 ,并异步写入数据库(mysql)
使用异步和请求包(NodeJS / Express)进行多个 API 调用