Receiving Shippo::Exceptions::APIServerError: Unable to read data received back from the server When trying new Shippo Shipment
Receiving Shippo::Exceptions::APIServerError: Unable to read data received back from the server When trying new Shippo Shipment
在使用 Shippo 运送的 Rails 4 应用程序中,我根据 the API docs 将以下哈希传递到 Shippo::Shipment.create(shippo_params):
{
:object_purpose => "PURCHASE",
:async => false,
:address_to => {
"object_purpose" => "PURCHASE",
"name" => "Test Guy",
"street1" => "5000 Test St",
"street2" => "",
"city" => "New Orleans",
"state" => "LA",
"zip" => "70115",
"country" => "US"
},
:address_from => {
"object_purpose" => "PURCHASE",
"company" => "MyCompany",
"street1" => "1305 Business Lane",
"street2" => "Suite O",
"city" => "New Orleans",
"state" => "LA",
"zip" => "70123",
"country" => "US",
"phone" => "+1 999 999 9999",
},
:parcel => {
"length" => 5,
"width" => 5,
"height" => 5,
"distance_unit" => :in,
"weight" => 1,
"mass_unit" => :lb
}
}
然后我收到错误:
Shippo::Exceptions::APIServerError: Unable to read data received back from the server.
如果我使用 API 中引用的以下参数散列,它会起作用:
params = { object_purpose: 'PURCHASE',
async: false,
address_from: {
object_purpose: 'PURCHASE',
name: 'Mr Hippo',
company: 'Shippo',
street1: '215 Clayton St.',
street2: '',
city: 'San Francisco',
state: 'CA',
zip: '94117',
country: 'US',
phone: '+1 555 341 9393',
email: 'support@goshippo.com' },
address_to: {
object_purpose: 'PURCHASE',
name: 'Mrs Hippo"',
company: 'San Diego Zoo',
street1: '2920 Zoo Drive',
city: 'San Diego',
state: 'CA',
zip: '92101',
country: 'US',
phone: '+1 555 341 9393',
email: 'hippo@goshippo.com' },
parcel: {
length: 5,
width: 2,
height: 5,
distance_unit: :in,
weight: 2,
mass_unit: :lb }
}
两者有细微差别,在调用检查时,前者在键中有一些转义引号,而另一个则没有,但我不知道为什么这很重要(或者为什么要设置它那样)。
谁能告诉我有什么区别以及为什么 Shippo 会返回此错误?
有两个问题:
- 在您的请求中,Address 对象未包含所有必填字段。这是对您的数据的工作请求 - 我向两个地址添加了电子邮件值,并向 address_from 对象添加了名称值:https://gist.github.com/simonkreuz/2da33c20d4015b0bc64079078db62ddc
- Shippo 的 Ruby 包装器无法正确解析返回的 API 错误消息。 API 实际上返回了一个错误,表明 Address 对象没有包含所有必填字段。我已经在此处 https://github.com/goshippo/shippo-ruby-client/issues/22.
向 Shippo 的工程团队提交了工单
在使用 Shippo 运送的 Rails 4 应用程序中,我根据 the API docs 将以下哈希传递到 Shippo::Shipment.create(shippo_params):
{
:object_purpose => "PURCHASE",
:async => false,
:address_to => {
"object_purpose" => "PURCHASE",
"name" => "Test Guy",
"street1" => "5000 Test St",
"street2" => "",
"city" => "New Orleans",
"state" => "LA",
"zip" => "70115",
"country" => "US"
},
:address_from => {
"object_purpose" => "PURCHASE",
"company" => "MyCompany",
"street1" => "1305 Business Lane",
"street2" => "Suite O",
"city" => "New Orleans",
"state" => "LA",
"zip" => "70123",
"country" => "US",
"phone" => "+1 999 999 9999",
},
:parcel => {
"length" => 5,
"width" => 5,
"height" => 5,
"distance_unit" => :in,
"weight" => 1,
"mass_unit" => :lb
}
}
然后我收到错误:
Shippo::Exceptions::APIServerError: Unable to read data received back from the server.
如果我使用 API 中引用的以下参数散列,它会起作用:
params = { object_purpose: 'PURCHASE',
async: false,
address_from: {
object_purpose: 'PURCHASE',
name: 'Mr Hippo',
company: 'Shippo',
street1: '215 Clayton St.',
street2: '',
city: 'San Francisco',
state: 'CA',
zip: '94117',
country: 'US',
phone: '+1 555 341 9393',
email: 'support@goshippo.com' },
address_to: {
object_purpose: 'PURCHASE',
name: 'Mrs Hippo"',
company: 'San Diego Zoo',
street1: '2920 Zoo Drive',
city: 'San Diego',
state: 'CA',
zip: '92101',
country: 'US',
phone: '+1 555 341 9393',
email: 'hippo@goshippo.com' },
parcel: {
length: 5,
width: 2,
height: 5,
distance_unit: :in,
weight: 2,
mass_unit: :lb }
}
两者有细微差别,在调用检查时,前者在键中有一些转义引号,而另一个则没有,但我不知道为什么这很重要(或者为什么要设置它那样)。
谁能告诉我有什么区别以及为什么 Shippo 会返回此错误?
有两个问题:
- 在您的请求中,Address 对象未包含所有必填字段。这是对您的数据的工作请求 - 我向两个地址添加了电子邮件值,并向 address_from 对象添加了名称值:https://gist.github.com/simonkreuz/2da33c20d4015b0bc64079078db62ddc
- Shippo 的 Ruby 包装器无法正确解析返回的 API 错误消息。 API 实际上返回了一个错误,表明 Address 对象没有包含所有必填字段。我已经在此处 https://github.com/goshippo/shippo-ruby-client/issues/22. 向 Shippo 的工程团队提交了工单