{"id":1412,"date":"2021-11-09T15:37:46","date_gmt":"2021-11-09T07:37:46","guid":{"rendered":"http:\/\/b.julym.com\/?p=1412"},"modified":"2021-11-09T15:56:53","modified_gmt":"2021-11-09T07:56:53","slug":"python-flask%e6%8a%a5%e9%94%99unicodedecodeerror","status":"publish","type":"post","link":"https:\/\/b.julym.com\/sharetutorial\/1412.html","title":{"rendered":"[Python] Flask\u62a5\u9519UnicodeDecodeError"},"content":{"rendered":"<p><img src=\"http:\/\/cdn.ncii.cn\/picbase\/imgs\/2021\/11\/64fc7a7227e16a16.png\" style=\"display: none;\" \/><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"monokai\">File \"C:\\Users\\hello\\Desktop\\py_project\\lib\\socket.py\", line 676, in getfqdn\r\n    hostname, aliases, ipaddrs = gethostbyaddr(name)\r\nUnicodeDecodeError: 'utf-8' codec can't decode byte 0xc1 in position 0: invalid start byte<\/pre>\n<p>\u4eca\u5929\u4e00\u4e2a\u9879\u76ee\u78b0\u5230\u8fd9\u4e2a\u62a5\u9519\uff0c\u4f46\u662f\u81ea\u5df1\u7684\u7535\u8111\u5374\u4e0d\u62a5\u9519\uff0c\u7528\u6237\u7684\u7535\u8111\u62a5\u9519\uff0c\u5c31\u611f\u89c9\u5f88\u5947\u602a\u3002<\/p>\n<h3>\u95ee\u9898\u5206\u6790<\/h3>\n<p>\u5b9a\u4f4d\u5230socket.py\u540e\u67e5\u770b\u6e90\u7801\u53d1\u73b0\u662f\u5728\u83b7\u53d6\u8ba1\u7b97\u673a\u540d\u79f0\u7684\u65f6\u5019\u83b7\u53d6\u5230\u4e2d\u6587\u62a5\u7684\u9519\uff08\u5c31\u662fhostname\u662f\u4e2d\u6587\u7684\uff0c\u7136\u540e\u521a\u597d\u81ea\u5df1\u7535\u8111\u7684hostname\u662f\u82f1\u6587\u7684\u6240\u4ee5\u4e0d\u62a5\u9519\uff09\uff0c\u800c\u4e14except error\u5e76\u4e0d\u80fd\u6355\u83b7\u5f02\u5e38\uff0c\u4f9d\u7136\u4f1a\u5728\u4e0b\u9762\u4ee3\u7801\u4e2d\u8c03\u7528\u51fa\u9519\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"monokai\">try:\r\n   hostname, aliases, ipaddrs = gethostbyaddr(name)\r\nexcept error:\r\n   pass<\/pre>\n<h3>\u89e3\u51b3\u65b9\u6cd5<\/h3>\n<p>\u6709\u4e24\u79cd\u65b9\u6cd5<\/p>\n<p>1.\u628a\u7535\u8111\u7684hostname\u6539\u6210\u82f1\u6587\u7684<\/p>\n<p>2.\u628a\u4e0a\u8ff0\u7684\u4ee3\u7801\u4fee\u6539\u4e3a\u4ee5\u4e0b\u5373\u53ef<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"monokai\">try:\r\n   hostname, aliases, ipaddrs = gethostbyaddr(name)\r\nexcept Exception as error:\r\n   name = \"Macro\"  #\u76f4\u63a5\u7ed9\u5b83\u8fd4\u56de\u4e00\u4e2a\u82f1\u6587\u540d<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>File &#8220;C:\\Users\\hello\\Desktop\\py_project\\lib\\socket.py&#8221;, line 676, in getfqdn hostname, aliases, ipaddrs = gethostbyaddr(name) UnicodeDecodeError: &#8216;utf [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[867,499],"tags":[946,868,947,948],"_links":{"self":[{"href":"https:\/\/b.julym.com\/wp-json\/wp\/v2\/posts\/1412"}],"collection":[{"href":"https:\/\/b.julym.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/b.julym.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/b.julym.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/b.julym.com\/wp-json\/wp\/v2\/comments?post=1412"}],"version-history":[{"count":3,"href":"https:\/\/b.julym.com\/wp-json\/wp\/v2\/posts\/1412\/revisions"}],"predecessor-version":[{"id":1417,"href":"https:\/\/b.julym.com\/wp-json\/wp\/v2\/posts\/1412\/revisions\/1417"}],"wp:attachment":[{"href":"https:\/\/b.julym.com\/wp-json\/wp\/v2\/media?parent=1412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/b.julym.com\/wp-json\/wp\/v2\/categories?post=1412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/b.julym.com\/wp-json\/wp\/v2\/tags?post=1412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}