{"id":822,"date":"2023-03-03T22:26:27","date_gmt":"2023-03-03T14:26:27","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=822"},"modified":"2023-04-29T16:52:09","modified_gmt":"2023-04-29T08:52:09","slug":"robot-framework-chinese-log-garbled-issue","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/03\/robot-framework-chinese-log-garbled-issue\/","title":{"rendered":"Robot Framework\u4e2d\u6587\u65e5\u5fd7\u4e71\u7801\u95ee\u9898"},"content":{"rendered":"<p>\u95ee\u9898\u63cf\u8ff0\uff1a\u63a5\u53e3\u3001\u6570\u636e\u5e93\u8fd4\u56de\u4fe1\u606f\u6709\u4e2d\u6587\u7684\u65f6\u5019\u63a7\u5236\u53f0\u6216\u65e5\u5fd7\u62a5\u544a\u4f1a\u663e\u793a\u4e71\u7801\u6216<code>unicode<\/code>\u7f16\u7801\u6837\u5f0f<\/p>\n<p>1\u3001\u67e5\u8be2SQL\u4e2d\u6587\u4e71\u7801\uff0c\u9700\u8981\u5728\u8fde\u63a5\u6570\u636e\u5e93\u65f6\uff0c\u5728\u7ed3\u5c3e\u5904\u6307\u5b9a\u7f16\u7801\u65b9\u5f0f\u3002\u5373\u5728 <code>pymysql<\/code> \u8fde\u63a5\u5c3e\u90e8\u52a0\u4e0a <code>charset='UTF8'<\/code> \u5373\u53ef\u3002\u4f8b\u5982\uff1a<\/p>\n<p><!-- more --><\/p>\n<pre><code>Connect to database using custom params    pymysql    host=&#039;127.0.0.1&#039;,port=3306,user=&#039;root&#039;,passwd=&#039;123456&#039;,db=&#039;test&#039;,charset=&#039;UTF8&#039;<\/code><\/pre>\n<p>2\u3001\u63a7\u5236\u53f0\u8bbe\u7f6e\u4e3a UTF-8\u5b57\u7b26\u96c6<\/p>\n<pre><code class=\"language-shell\">> chcp 65001\n> python ride.py<\/code><\/pre>\n<p>3\u3001\u4fee\u6539unic.py\u6587\u4ef6<\/p>\n<p>\u82e5Robot Framework\u4e3a3.0.X\uff0c\u627e\u5230python\u5b89\u88c5\u76ee\u5f55\u4e0b\u7684\\Lib\\site-packages\\robot\\utils\\unic.py\u6587\u4ef6<\/p>\n<p>\u5f15\u5165json\u5e93\uff1a<\/p>\n<pre><code class=\"language-python\">import json<\/code><\/pre>\n<p>\u5c06\u4e0b\u9762\u4ee3\u7801\u590d\u5236\u5230\u5982\u56fe\u4f4d\u7f6e\uff0c\u6ce8\u610f\u5bf9\u9f50\u65b9\u5f0f<\/p>\n<pre><code class=\"language-python\">if isinstance(item, (list, dict, tuple)):\n   try:\n       item = json.dumps(item, ensure_ascii=False, encoding=&#039;cp936&#039;)\n   except UnicodeDecodeError:\n       try:\n           item = json.dumps(item, ensure_ascii=False, encoding=&#039;cp936&#039;)\n       except:\n           pass\n   except:\n       pass<\/code><\/pre>\n<blockquote>\n<p>\u5176\u4e2d\u7684cp936\u53ef\u7528utf-8\u6216\u8005gbk\u7f16\u7801\u683c\u5f0f\u53bb\u66ff\u6362<\/p>\n<\/blockquote>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/\u6d4b\u8bd5\/robot_\u4e2d\u6587_unic.png\" alt=\"Robot Framework\u4e2d\u6587\u65e5\u5fd7\u4e71\u7801\u95ee\u9898\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u9898\u63cf\u8ff0\uff1a\u63a5\u53e3\u3001\u6570\u636e\u5e93\u8fd4\u56de\u4fe1\u606f\u6709\u4e2d\u6587\u7684\u65f6\u5019\u63a7\u5236\u53f0\u6216\u65e5\u5fd7\u62a5\u544a\u4f1a\u663e\u793a\u4e71\u7801\u6216unicode\u7f16\u7801\u6837\u5f0f 1\u3001\u67e5\u8be2SQL\u4e2d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[228],"tags":[227],"class_list":["post-822","post","type-post","status-publish","format-standard","hentry","category-robot-framework","tag-robot-framework"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/822","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=822"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/822\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=822"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=822"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=822"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}