{"id":26478,"date":"2024-11-24T17:24:00","date_gmt":"2024-11-24T09:24:00","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26478\/"},"modified":"2024-11-24T17:24:00","modified_gmt":"2024-11-24T09:24:00","slug":"python3-%e5%a4%84%e7%90%86%e6%95%b0%e6%8d%ae%e5%ba%93%e6%97%b6%e6%8a%a5%e9%94%99%e5%a4%84%e7%90%86%e4%b8%ad-%ef%bc%8c%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26478\/","title":{"rendered":"Python3 \u5904\u7406\u6570\u636e\u5e93\u65f6\u62a5\u9519\u201c\u5904\u7406\u4e2d&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;\u201d\uff0c\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173096046448399.jpg\" class=\"aligncenter\" title=\"Python3 \u5904\u7406\u6570\u636e\u5e93\u65f6\u62a5\u9519\u201c\u5904\u7406\u4e2d&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;\u201d\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"Python3 \u5904\u7406\u6570\u636e\u5e93\u65f6\u62a5\u9519\u201c\u5904\u7406\u4e2d&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;\u201d\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>3 \u62a5\u9519\uff1f<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u5728\u5904\u7406\u6570\u636e\u5e93\u4e2d\u6267\u884c\u65f6\uff0c\u6536\u5230\u9519\u8bef\u63d0\u793a\uff1a\u201c\u5904\u7406\u4e2d&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;\u201d\u3002<\/p>\n<p><strong>\u56de\u7b54\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u4f60\u7684\u4ee3\u7801\u4e2d\u4f7f\u7528\u4e86\u4e8b\u52a1\u548c\u56de\u6eda\uff0c\u4f46\u5b9e\u9645\u4e0a\u6839\u672c\u4e0d\u9700\u8981\u8fd9\u4e9b\u64cd\u4f5c\u3002\u4ee5\u4e0b\u662f\u4fee\u6b63\u540e\u7684\u4ee3\u7801\u7247\u6bb5\uff1a<\/p>\n<pre>import requests\nimport time\nimport json\nimport pymysql\n\nmydb = pymysql.connect(\n    host=\"92.68.40.12\", port=3306,\n    user=\"root\",\n    password=\"iss_root\",\n    database=\"dynamic_premium_db\"\n)\nmycursor = mydb.cursor()\n\ndef 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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4fee\u6539\u540e\u7684\u4ee3\u7801\u79fb\u9664\u4e86\u4e8b\u52a1\u548c\u56de\u6eda\u64cd\u4f5c\uff0c\u76f4\u63a5\u6267\u884csql\u8bed\u53e5\u63d2\u5165\u6570\u636e\u3002\u4f7f\u7528 try&#8230;except \u8bed\u53e5\u6355\u83b7\u5e76\u5904\u7406\u4efb\u4f55\u9519\u8bef\uff0c\u5e76\u5728\u63d2\u5165\u6210\u529f\u65f6\u6253\u5370\u4fe1\u606f\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fPython3 \u5904\u7406\u6570\u636e\u5e93\u65f6\u62a5\u9519\u201c\u5904\u7406\u4e2d&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;\u201d\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>3 \u62a5\u9519\uff1f \u95ee\u9898\uff1a \u5728\u5904\u7406\u6570\u636e\u5e93\u4e2d\u6267\u884c\u65f6\uff0c\u6536\u5230\u9519\u8bef\u63d0\u793a\uff1a\u201c\u5904\u7406\u4e2d&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;\u201d\u3002 \u56de\u7b54\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u4f60\u7684\u4ee3\u7801\u4e2d\u4f7f\u7528\u4e86\u4e8b\u52a1\u548c\u56de\u6eda\uff0c\u4f46\u5b9e\u9645\u4e0a\u6839\u672c\u4e0d\u9700\u8981\u8fd9\u4e9b\u64cd\u4f5c\u3002\u4ee5\u4e0b\u662f\u4fee\u6b63\u540e\u7684\u4ee3\u7801\u7247\u6bb5\uff1a import requests import time import json import pymysql mydb = pymysql.connect( host=&#8221;92.68.40.12&#8243;, port=3306, user=&#8221;root&#8221;, password=&#8221;iss_root&#8221;, database=&#8221;dynamic_premium_db&#8221; ) mycursor = mydb.cursor() def excute_sql_db(stratagy_id, city_id, app_name, total_price, over_flow_price, date_time): sql = &#8220;INSERT INTO over_flow_price(straragy_id,city_id,app_name,total_price,over_flow_price,time_stamp)VALUES(&#8216;%s&#8217;,&#8217;%s&#8217;,&#8217;%s&#8217;,&#8217;%s&#8217;,&#8217;%s&#8217;,&#8217;%s&#8217;)&#8221; % ( stratagy_id, city_id, app_name, total_price, over_flow_price, date_time) try: mycursor.execute(sql) print(&#8216;\u63d2\u5165\u6210\u529f&#8217;) except Exception as e: print(&#8216;err: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-26478","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=26478"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26478\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}