{"id":6967,"date":"2019-01-13T22:07:44","date_gmt":"2019-01-13T21:07:44","guid":{"rendered":"https:\/\/pi3g.com\/?p=6967"},"modified":"2019-01-13T22:07:44","modified_gmt":"2019-01-13T21:07:44","slug":"exception-unexpected-quote-at-12-csvmalformedcsverror-crystal","status":"publish","type":"post","link":"https:\/\/pi3g.com\/de\/exception-unexpected-quote-at-12-csvmalformedcsverror-crystal\/","title":{"rendered":"Exception: Unerwartetes Zitat bei 1:2 (CSV::MalformedCSVError) Crystal"},"content":{"rendered":"<p>Beim Versuch, eine Amazon-Zahlungsdatei zu analysieren, bin ich \u00fcber dieses spezielle Problem gestolpert:<\/p>\n<p>Exception: Unerwartetes Zitat bei 1:2 (CSV::MalformedCSVError)<\/p>\n<p>Der Grund daf\u00fcr: Amazon Pay kodiert seine Dateien in UTF-8 mit BOM. Das BOM ist eine optionale (in UTF-8-Dateien) Markierung. Sie k\u00f6nnen es zum Beispiel mit dem Tool xxd sehen<\/p>\n<blockquote>\n<p>xxd apolish_amazon_2018DecMonthlyTransaction.csv | less<\/p>\n<\/blockquote>\n<p><a href=\"https:\/\/pi3g.com\/wp-content\/uploads\/2019\/01\/image-31.png\"><img loading=\"lazy\" decoding=\"async\" width=\"976\" height=\"40\" title=\"Bild\" style=\"display: inline; background-image: none;\" alt=\"Bild\" src=\"https:\/\/pi3g.com\/wp-content\/uploads\/2019\/01\/image_thumb-30.png\" border=\"0\"><\/a><\/p>\n<p>Die drei Punkte am Anfang der Datei sind die BOM. (EF BB BF in Hex).<\/p>\n<h3>Der Umgang mit der BOM<\/h3>\n<p>Die Einstellung einer anderen Dateikodierung hilft leider nicht, da iconv die BOM anscheinend unver\u00e4ndert weitergibt.<\/p>\n<p>Es gibt keine \"speziellen\" Kodierungsvarianten, die Sie verwenden k\u00f6nnten, siehe <a href=\"https:\/\/pi3g.com\/de\/2018\/11\/24\/the-crystal-programming-language-and-encodings\/\" target=\"_blank\">meine Liste f\u00fcr iconv hier<\/a>.<\/p>\n<p>Daher m\u00fcssen wir sie durch das Lesen von drei Bytes entfernen.<\/p>\n<blockquote>\n<p>apf = File.open(mein_dateiname)<br \/><strong><br \/>\ndiscard = apf.gets(3)<\/strong><br \/>\nputs (discard.inspect)<br \/>\napf.set_encoding(\"UTF-8\", nil)\n<\/p>\n<\/blockquote>\n<p>\n<\/p>\n<p><\/p>\n<h3>Lesen Sie weiter:<\/h3>\n<ul>\n<li><a href=\"https:\/\/zzz.buzz\/2016\/07\/30\/bom-in-iconv\/#remove-bom-in-utf-8-encoded-files\">https:\/\/zzz.buzz\/2016\/07\/30\/bom-in-iconv\/#remove-bom-in-utf-8-encoded-files<\/a><\/li>\n<li><a href=\"https:\/\/crystal-lang.org\/api\/0.27.0\/IO.html\">https:\/\/crystal-lang.org\/api\/0.27.0\/IO.html<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Beim Versuch, eine Amazon Pay-Datei zu analysieren, bin ich \u00fcber dieses spezielle Problem gestolpert: Exception: Unerwartetes Zitat bei 1:2 (CSV::MalformedCSVError) Der Grund: Amazon Pay kodiert seine Dateien in UTF-8 mit BOM. Das BOM ist eine optionale (in UTF-8-Dateien) Markierung. Sie k\u00f6nnen es mit dem Tool xxd sehen, z.B. xxd apolish_amazon_2018DecMonthlyTransaction.csv | less Die...<\/p>","protected":false},"author":830,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[416],"tags":[480,475,477,476,478,479],"class_list":["post-6967","post","type-post","status-publish","format-standard","hentry","category-crystal-language","tag-amazon-pay","tag-bom-utf-8","tag-crystal-lang","tag-crystal-language","tag-csv","tag-parsing"],"_links":{"self":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts\/6967","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/users\/830"}],"replies":[{"embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/comments?post=6967"}],"version-history":[{"count":1,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts\/6967\/revisions"}],"predecessor-version":[{"id":6968,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/posts\/6967\/revisions\/6968"}],"wp:attachment":[{"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/media?parent=6967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/categories?post=6967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pi3g.com\/de\/wp-json\/wp\/v2\/tags?post=6967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}