{"id":5052,"date":"2022-06-21T16:55:00","date_gmt":"2022-06-21T08:55:00","guid":{"rendered":"http:\/\/www.menglanglang.cn\/?p=5052"},"modified":"2022-06-22T23:39:02","modified_gmt":"2022-06-22T15:39:02","slug":"premature-end-of-script-headers-%e6%88%96-end-of-script-output-before-headers","status":"publish","type":"post","link":"http:\/\/www.menglanglang.cn\/?p=5052","title":{"rendered":"Premature end of script headers \u6216 End of script output before headers"},"content":{"rendered":"\n<p>\u200b\u5728\u6d4b\u8bd5 Python DB-API \u4f7f\u7528\u6d41\u7a0b\u811a\u672c\u65f6\uff0c\u8bbf\u95ee\u51fa\u73b0\u5982\u4e0b\u9519\u8bef\uff1a<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"201\" width=\"900\" src=\"\/\/images.weserv.nl\/?url=https:\/\/img-blog.csdnimg.cn\/f99f7425e1084154824b81705fa0b204.png\" alt=\"\"\/>\u200b<\/p>\n\n\n\n<p>\u67e5\u770b Apache \u65e5\u5fd7\uff0c\u9519\u8bef\u4fe1\u606f\u5982\u4e0b\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Premature end of script headers: dblink.py<\/p><p>\u6216\u8005<\/p><p>End of script output before headers: dblink.py<\/p><\/blockquote>\n\n\n\n<p>dblink.py \u811a\u672c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/python\n# -*- coding: UTF-8 -*-\n\nimport MySQLdb\n\n# \u6253\u5f00\u6570\u636e\u5e93\u8fde\u63a5\ndb = MySQLdb.connect(\"localhost\", \"\u6570\u636e\u5e93\u7528\u6237\u540d\", \"\u6570\u636e\u5e93\u5bc6\u7801\", \"\u6570\u636e\u5e93\", charset='utf8mb4')\n\n# \u4f7f\u7528cursor()\u65b9\u6cd5\u83b7\u53d6\u64cd\u4f5c\u6e38\u6807\ncursor = db.cursor()\n\n# \u4f7f\u7528execute\u65b9\u6cd5\u6267\u884cSQL\u8bed\u53e5\ncursor.execute(\"SELECT VERSION()\")\n\n# \u4f7f\u7528 fetchone() \u65b9\u6cd5\u83b7\u53d6\u4e00\u6761\u6570\u636e\ndata = cursor.fetchone()\n\nprint \"Database version : %s \" % data\n\n# \u5173\u95ed\u6570\u636e\u5e93\u8fde\u63a5\ndb.close()<\/code><\/pre>\n\n\n\n<p>\u901a\u8fc7\u8c03\u8bd5\u53d1\u73b0\uff0c\u5e94\u8be5\u662f\u6ca1\u6709\u6807\u8bb0 HTTP \u5934\u90e8\u4fe1\u606f\u7ed3\u675f\u5bfc\u81f4\uff0c\u7a0b\u5e8f\u4fee\u6539\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/python\n# -*- coding: UTF-8 -*-\n\nimport MySQLdb\n\n# \u6253\u5f00\u6570\u636e\u5e93\u8fde\u63a5\ndb = MySQLdb.connect(\"localhost\", \"\u6570\u636e\u5e93\u7528\u6237\u540d\", \"\u6570\u636e\u5e93\u5bc6\u7801\", \"\u6570\u636e\u5e93\", charset='utf8mb4')\n\n# \u4f7f\u7528cursor()\u65b9\u6cd5\u83b7\u53d6\u64cd\u4f5c\u6e38\u6807\ncursor = db.cursor()\n\n# \u4f7f\u7528execute\u65b9\u6cd5\u6267\u884cSQL\u8bed\u53e5\ncursor.execute(\"SELECT VERSION()\")\n\n# \u4f7f\u7528 fetchone() \u65b9\u6cd5\u83b7\u53d6\u4e00\u6761\u6570\u636e\ndata = cursor.fetchone()\n\nprint \"Content-type:text\/html\"\nprint                               # \u7a7a\u884c\uff0c\u544a\u8bc9\u670d\u52a1\u5668\u7ed3\u675f\u5934\u90e8\nprint \"Database version : %s \" % data\n\n# \u5173\u95ed\u6570\u636e\u5e93\u8fde\u63a5\ndb.close()<\/code><\/pre>\n\n\n\n<p>\u5176\u4e2d\uff0c\" Content-type:text\/html\" \u4e3a HTTP \u5934\u90e8\u7684\u4e00\u90e8\u5206\uff0c\u5b83\u4f1a\u53d1\u9001\u7ed9\u6d4f\u89c8\u5668\u5e76\u544a\u8bc9\u6d4f\u89c8\u5668\u6587\u4ef6\u7684\u5185\u5bb9\u7c7b\u578b\uff0c\u7528 print \u8f93\u51fa\u4e00\u4e2a\u7a7a\u884c\u7528\u4e8e\u544a\u8bc9\u670d\u52a1\u5668\u7ed3\u675f\u5934\u90e8\u4fe1\u606f\u3002<\/p>\n\n\n\n<p>\u8bbf\u95ee\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" height=\"49\" width=\"349\" src=\"\/\/images.weserv.nl\/?url=https:\/\/img-blog.csdnimg.cn\/40c641f11ffb4c50ae1a7ece9fa3d36c.png\" alt=\"\"\/><\/p>\n\n\n\n<p>\u200b\u539f\u6587\u94fe\u63a5\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/blog.csdn.net\/tzhuwb\/article\/details\/125393767\" target=\"_blank\">https:\/\/blog.csdn.net\/tzhuwb\/article\/details\/125393767<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u200b\u5728\u6d4b\u8bd5 Python DB-API \u4f7f\u7528\u6d41\u7a0b\u811a\u672c\u65f6\uff0c\u8bbf\u95ee\u51fa\u73b0\u5982\u4e0b\u9519\u8bef\uff1a \u200b \u67e5\u770b Apache \u65e5\u5fd7\uff0c\u9519\u8bef\u4fe1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[812],"tags":[863,335,186,813,799],"class_list":["post-5052","post","type-post","status-publish","format-standard","hentry","category-python","tag-db-api","tag-error","tag-mysql","tag-python","tag-799"],"_links":{"self":[{"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=\/wp\/v2\/posts\/5052","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5052"}],"version-history":[{"count":1,"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=\/wp\/v2\/posts\/5052\/revisions"}],"predecessor-version":[{"id":5053,"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=\/wp\/v2\/posts\/5052\/revisions\/5053"}],"wp:attachment":[{"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5052"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.menglanglang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}