{"id":200524,"date":"2025-05-06T11:58:33","date_gmt":"2025-05-06T03:58:33","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200524\/"},"modified":"2025-05-06T11:58:33","modified_gmt":"2025-05-06T03:58:33","slug":"python3%e7%a8%8b%e5%ba%8f%e6%8a%a5%e9%94%99err-sql%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200524\/","title":{"rendered":"Python3\u7a0b\u5e8f\u62a5\u9519\u201cerr: + sql\u201d\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Python3\u7a0b\u5e8f\u62a5\u9519\u201cerr: + sql\u201d\u5982\u4f55\u89e3\u51b3\uff1f<\/h1>\n<p>\u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929\u4e3b\u673a\u5b9d\u8d1d\u5c31\u6574\u7406\u5206\u4eab\u300aPython3\u7a0b\u5e8f\u62a5\u9519\u201cerr: + sql\u201d\u5982\u4f55\u89e3\u51b3\uff1f\u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u5982\u679c\u4f60\u5bf9\u6570\u636e\u5e93\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\u4e3b\u673a\u5b9d\u8d1d\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241107\/1730965185672c6ec12c640.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>python3\u7a0b\u5e8f\u62a5\u9519\u201cerr: + sql\u201d\u5982\u4f55\u89e3\u51b3\uff1f<\/strong><\/p>\n<p>\u5728\u6267\u884c\u5982\u4e0b python \u4ee3\u7801\u65f6\uff0c\u9047\u5230\u4e86\u9519\u8bef\u201cerr: + sql\u201d\uff1a<\/p>\n<pre>def excute_sql_db(stratagy_id, city_id, app_name, total_price, over_flow_price, date_time):\n    sql = \"insert into over_flow_price(straragy_id,city_id,app_name,total_price,over_flow_price,time_stamp)values('%s','%s','%s','%s','%s','%s')\" % (\n        stratagy_id, city_id, app_name, total_price, over_flow_price, date_time)\n    try:\n        mycursor.execute(sql)\n        print('\u63d2\u5165\u6210\u529f')\n    except exception as e:\n        print('err: ' + sql)\n        print(e)<\/pre>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u5f15\u53d1\u6b64\u9519\u8bef\u7684\u539f\u56e0\u662f\uff0c\u5728 sql \u8bed\u53e5\u7684\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u8fc7\u7a0b\u4e2d\uff0c\u5c06 sql \u5b57\u7b26\u4e32\u548c\u9519\u8bef\u4fe1\u606f\u8fdb\u884c\u62fc\u63a5\uff0c\u800c\u4e0d\u662f\u5c06\u9519\u8bef\u4fe1\u606f\u4f5c\u4e3a\u5f02\u5e38\u4fe1\u606f\u62a5\u544a\u3002\u6b63\u786e\u7684\u65b9\u6cd5\u662f\uff0c\u5c06\u9519\u8bef\u4fe1\u606f\u4f5c\u4e3a\u5f02\u5e38\u629b\u51fa\uff0c\u800c\u4e0d\u662f\u6253\u5370\u5728\u63a7\u5236\u53f0\u4e0a\u3002<\/p>\n<p>\u4fee\u6b63\u8fc7\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>def excute_sql_db(stratagy_id, city_id, app_name, total_price, over_flow_price, date_time):\n    sql = \"INSERT INTO over_flow_price(straragy_id,city_id,app_name,total_price,over_flow_price,time_stamp)VALUES('%s','%s','%s','%s','%s','%s')\" % (\n        stratagy_id, city_id, app_name, total_price, over_flow_price, date_time)\n    try:\n        mycursor.execute(sql)\n        print('\u63d2\u5165\u6210\u529f')\n    except Exception as e:\n        raise Exception('err: ' + sql)<\/pre>\n<p>\u4fee\u6b63\u540e\u7684\u4ee3\u7801\u5c06\u5f02\u5e38\u4fe1\u606f\u4f5c\u4e3a\u5f02\u5e38\u629b\u51fa\uff0c\u800c\u4e0d\u662f\u6253\u5370\u5728\u63a7\u5236\u53f0\u4e0a\uff0c\u4ece\u800c\u6b63\u786e\u5904\u7406\u9519\u8bef\u3002<\/p>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aPython3\u7a0b\u5e8f\u62a5\u9519\u201cerr: + sql\u201d\u5982\u4f55\u89e3\u51b3\uff1f\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>Python3\u7a0b\u5e8f\u62a5\u9519\u201cerr:&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200524","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200524","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200524"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200524\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}