在一个使用Shippo的Rails 4应用程序中,我将下面的散列传递给Shippo::Shipment.create(shippo_params),如API文档所示
{
: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散列,它可以工作:
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 }
}两者之间有细微的区别,在调用in时,前者在键中有一些转义引号,而另一个没有,但我不知道这有什么关系(或者为什么会这样设置)。
有人能告诉我有什么区别吗?为什么Shippo会返回这个错误?
发布于 2016-09-15 22:49:34
有两个问题:
https://stackoverflow.com/questions/39516219
复制相似问题