首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >scala中的Easypost

scala中的Easypost
EN

Stack Overflow用户
提问于 2017-03-01 06:27:18
回答 2查看 131关注 0票数 0

我试图通过提供他们的邮编从用户地点到仓库地点收取运费。我必须在scala中实现它,所以我尝试使用他们的Java。下面是我使用的代码-

代码语言:javascript
复制
var fromAddressMap:HashMap[String,Object]=new util.HashMap[String,Object]
fromAddressMap.put("zip",warehouse_zip)
var toAddressMap:HashMap[String,Object]=new util.HashMap[String,Object]
toAddressMap.put("zip",user_zip)
var parcelMap:HashMap[String,Object]=new util.HashMap[String,Object]
parcelMap.put("weight", "22")
parcelMap.put("height", "12")
parcelMap.put("width", "8")
parcelMap.put("length", "19")
val fromAddress:Address=Address.create(fromAddressMap)
val toAddress:Address=Address.create(toAddressMap)
val parcel:Parcel = Parcel.create(parcelMap)
val shipmentMap:HashMap[String,Object]=new util.HashMap[String,Object]
shipmentMap.put("to_address",toAddress)
shipmentMap.put("from_address",fromAddress)
shipmentMap.put("parcel", parcel)
val buyCarriers= new util.ArrayList[String]
buyCarriers.add("USPS")
val buyServices= new util.ArrayList[String]
buyServices.add("PriorityMailInternational")
var shipment = Shipment.create(shipmentMap)
shipment = shipment.buy(shipment.lowestRate(buyCarriers, buyServices))
println("Price is "+shipment.prettyPrint())

我得到的只是一个例外:

代码语言:javascript
复制
com.easypost.exception.EasyPostException: Unable to find lowest rate matching required criteria.

我甚至尝试使用curl命令,例如:

代码语言:javascript
复制
curl -X POST https://api.easypost.com/v2/shipments \
  -u <Easypost api key>: \
  -d 'shipment[to_address][name]=Dr. Steve Brule' \
   -d 'shipment[to_address][street1]=179 N Harbor Dr' \
   -d 'shipment[to_address][city]=Redondo Beach' \
   -d 'shipment[to_address][state]=CA' \
   -d 'shipment[to_address][zip]=90277' \
   -d 'shipment[to_address][country]=US' \
   -d 'shipment[to_address][phone]=8573875756' \
   -d 'shipment[to_address][email]=dr_steve_brule@gmail.com' \
   -d 'shipment[from_address][name]=EasyPost' \
   -d 'shipment[from_address][street1]=417 Montgomery Street' \
   -d 'shipment[from_address][street2]=5th Floor' \
   -d 'shipment[from_address][city]=San Francisco' \
   -d 'shipment[from_address][state]=CA' \
   -d 'shipment[from_address][zip]=94104' \
   -d 'shipment[from_address][country]=US' \
   -d 'shipment[from_address][phone]=4153334445' \
   -d 'shipment[from_address][email]=support@easypost.com' \
   -d 'shipment[parcel][length]=20.2' \
   -d 'shipment[parcel][width]=10.9' \
   -d 'shipment[parcel][height]=5' \
   -d 'shipment[parcel][weight]=65.9'

这是在他们的例子中给出的。但我错了:

代码语言:javascript
复制
curl: (77) error setting certificate verify locations:
  CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none

知道我该怎么做吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-11-25 17:51:35

我也收到了同样的错误,但是在Java中,我自己实现了一个getLowestRate()方法,而不是使用EasyPost,这里是一个java示例:

代码语言:javascript
复制
Rate selectedRate = null;
for(Rate r : shipment.getRates()) {
  if(selectedRate == null) {
    selectedRate = r;
  }
  if(r.getRate() < selectedRate.getRate()) {
    selectedRate = r;
  }
}

if(selectedRate == null) {
  log.error("Selected rate is null could not find any rates to iteRATE through...");
}

try {
  return shipment.buy(selectedRate);
} catch(EasyPostException e) {
  log.error("Failed to purchase a shipment at the lowest rate for shipment: {}", shipment);
}
票数 1
EN

Stack Overflow用户

发布于 2017-03-01 06:58:53

正如您的错误信息所述,您的错误似乎是系统中的一个问题。尝试搜索该错误,可能是How do I deal with certificates using cURL while trying to access an HTTPS url?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42524701

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档