lineofflight / peddler

Amazon Selling Partner API (SP-API) in Ruby
https://lineofflight.github.io/peddler/
MIT License
307 stars 130 forks source link

ArgumentError: unknown encoding name - utf8 for chinese header #147

Closed leoplct closed 4 years ago

leoplct commented 4 years ago

I am receiving this error. ArgumentError: unknown encoding name - utf8 [GEM_ROOT]/gems/peddler-2.1.1/lib/peddler/headers.rb:50:infind'`

Last response {"ReportType"=>"_GET_MERCHANT_LISTINGSDATA", "ReportProcessingStatus"=>"DONE", "EndDate"=>"2020-05-08T14:56:02+00:00", "Scheduled"=>"false", "ReportRequestId"=>"54774018390", "StartedProcessingDate"=>"2020-05-08T14:56:07+00:00", "SubmittedDate"=>"2020-05-08T14:56:02+00:00", "StartDate"=>"2020-05-08T14:56:02+00:00", "CompletedDate"=>"2020-05-08T14:56:13+00:00", "GeneratedReportId"=>"21572946398018390"}

Code

client = MWS::Reports::Client.new( 
      marketplace: "marketplace_stringid",
      merchant_id: "merchant_id",
      auth_token: "token",
      aws_access_key_id: 'XXXX',
      aws_secret_access_key: 'XXXX'
   )

...

client.get_report(report_id).parse
hakanensari commented 4 years ago

Sounds the same as #144. Could you upgrade the gem?

leoplct commented 4 years ago

After run "bundle update peddler" I am receiving the same error

[GEM_ROOT]/gems/peddler-2.4.1/lib/peddler/headers.rb:53:in `find'

hakanensari commented 4 years ago

@leoplct The above change will hopefully squash this bug. Could you test with the master and see if it works?

leoplct commented 4 years ago

It doesn't return error, but it can't parse the FlatFile. All values are nil. Here the first row of Flat file .content(). It's UK marketplace localized in Chinese.

商品名称 商品描述 商品编码 卖家 SKU 价格 数量 开售日期 不适用项目 是否为商城中的商品 商品编码类型 不适用项目 商品备注 商品状况 不适用项目 不适用项目 不适用项目 ASIN1 不适用项目 不适用项目 国际配送 加急配送 不适用项目 商品编码 不适用项目 添加-删除 等待购买数量配送渠道 企业商品价格 数量折扣价格类型 数量下限 1 数量折扣价格 1 数量下限 2 数量折扣价格 2 数量下限 3 数量折扣价格 3 数量下限 4 数量折扣价格 4 数量下限 5 数量折扣价格 5 卖家配送组

Few possible solutions:

  1. A mapping between the localized header and English standard (eg. asin_colum = row.match(/english-name|french-name|german-name|chinese-name/)
  2. Set through API the Feed Processing Report Language to english (but I haven't find the method)

Mapping all possible columns would be too much, maybe only the main ones enough. asin: row.field("asin1"), sku: row.field("seller-sku"), title: row.field("item-name"), image: row.field('image-url'), price: row.field('price').to_f, quantity: row.field('quantity').to_i

hakanensari commented 4 years ago

It sounds like your flat file is not working with the formatting options in the existing parser. Could you attach the response body (the first couple of lines, at least) so I check its formatting?

leoplct commented 4 years ago
商品名称    商品描述    商品编码    卖家 SKU  价格  数量  开售日期    不适用项目   是否为商城中的商品   商品编码类型  不适用项目   商品备注    商品状况    不适用项目   不适用项目   不适用项目   ASIN1   不适用项目   不适用项目   国际配送    加急配送    不适用项目   商品编码    不适用项目   添加-删除   等待购买数量  配送渠道    企业商品价格  数量折扣价格类型    数量下限 1  数量折扣价格 1    数量下限 2  数量折扣价格 2    数量下限 3  数量折扣价格 3    数量下限 4  数量折扣价格 4    数量下限 5  数量折扣价格 5    卖家配送组
Waterproof Sunshade Cover (180 * 180, Blue) Material: Waterproof and UV resistant Oxford cloth <br><br> Color: green black blue <br><br> Product Size: <br> <br> 120 * 120CM weight 210g <br> <br> 150 * 150CM weight 290g <br><br> 180 * 180CM weight 380g <br><br> 200 * 200CM weight 460g    0645YNJ5NZ9 04-AFWM-8QDS    20.32   10  15/04/2020 15:15:46 BST     y   4           11              B2884WQWZY                      4716528214404           0   DEFAULT             Migrated Template
Cover Rain And Snow Cover (242 * 160 * 100) Color: green can be customized <br><br> Fabric main component content: waterproof 210D Oxford cloth <br><br> Dimensions: length * width * height cm <br><br> size and weight: <br><br> 242 * 162 * 100cm weight 950g <br><br> 308 * 138 * 89cm weight 950g <br><br> 213 * 132 * 70cm weight 590g <br><br> 180 * 120 * 70cm weight 500g <br><br> 126 * 126 * 74cm weight 430g <br><br> 123 * 61 * 72cm weight 280g <br><br> 115 * 115 * 70cm weight 280g <br><br> 315 * 160 * 70cm weight 910g <br><br> 230 * 165 * 70cm weight 720g <br><br> 210 * 140 * 70cm weight 600g <br><br> 210 * 110 * 70cm weight 540g <br><br> 205 * 104 * 71cm weight 510g <br><br> 170 * 71 * 94cm weight 450g <br><br> 160 * 160 * 70cm weight 560g <br><br> 150 * 150 * 70cm weight 510g <br><br> 152 * 104 * 71cm weight 420g <br><br> 250 * 250 * 90cm weight 1190g 0416XWWK0U5 02-5QLY-0EFL    35.29   10  16/04/2020 15:01:43 BST     y   4           11              B0234CWWCC                      4714528214534           0   DEFAULT                                                 Migrated Template
hakanensari commented 4 years ago

@leoplct, so strictly speaking, Peddler does parse the flat file, but the issue is you're not able to use the English headers you would expect MWS to return—e.g. you're getting '卖家 SKU' in place of 'seller-sku'.

Yes, this is annoying, but I think it's best you handle this outside of Peddler as we don't have the data to abstract this properly for every locale and report type. I'm quite sure there are other locales and report types that similarly return translated headers.

Also, I don't think there's a way to ask the API to return the standard English headers. But maybe you can find another report type with the data you need that has less-legacy formatting?

leoplct commented 4 years ago

Ok, Do you know what's the simplest report to get all ASIN/SKUs for FBA+MFN with inventory > 0 ?

I only need these attributes:

hakanensari commented 4 years ago

@leoplct no answer off the top of my head—you have to go through the various inventory report types if you haven't already done so.