gpt4 book ai didi

Python 谷歌 API 构建

转载 作者:行者123 更新时间:2023-11-29 12:26:52 25 4
gpt4 key购买 nike

我一直在尝试将一段 html 上传到 MySQL 表中,但收到一条错误消息,但就问题的确切位置而言,它有点令人困惑。代码如下(这不是全部代码,只是冲突区域):

from mysql import connector
import time

def send(self, config, query, queryData):
cnx = connector.connect(**config)
cursor = cnx.cursor()
cursor.execute(query, queryData)
cursor.close()
cnx.close()

#this grabs the list of the succesfulyCapturedPackages and uploads to the wp_posts table.
def upload(self):
txtdate = time.strftime("%m-%d-%Y")
for pkg in self.succesfullyCaptured:
filename = pkg + ".html"
with open(filename,'r') as f:
package_post = f.read()
current_timestamp = time.strftime('%Y-%m-%d %H:%M:%S')
trimmed_package_name = pkg.lower()
trimmed_package_name = trimmed_package_name.replace(" ","-")
tup = self.fetch(self.configExternalDB,"SELECT MAX(ID) from wp_posts")
webURL = "http://www.AWORDPRESSSITE.com/?p=" + str(int(tup[0][0]) + 1)
package_post = connector.conversion.MySQLConverter().escape(package_post)

add_pkg_data = ("INSERT INTO wp_posts (post_author, post_date,"
"post_date_gmt, post_content, post_title, post_status,"
"comment_status, ping_status, post_name, "
"post_modified, post_modified_gmt, "
"post_parent, guid, menu_order, post_type, "
"comment_count) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, "
"%s, %s, %s, %s, %s, %s, %s,)")

data_pkg = (1, current_timestamp, current_timestamp, package_post,
pkg, 'draft', 'open', 'open', trimmed_package_name,
current_timestamp, current_timestamp, 0, webURL, 0, 'post', 0)

self.send(self.configExternalDB , add_pkg_data, data_pkg)

现在我得到的是以下内容:

mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

顺便说一句,我试图捕获的 HTML block 看起来有点像这样:

<h5><span lang=\"ES-MX\"> text text text $ 1000  USD +  755.00 text text días</span></h5>\n<h6><span lang=\"ES-MX\">Text: Text / Text / Text / Text</span></h6>\n<!--more--><span style=\"font-weight: 600; color: #222222;\">[google-map-v3 shortcodeid=\"TO_BE_GENERATED\" width=\"100%\" height=\"350\" zoom=\"12\" maptype=\"roadmap\" mapalign=\"center\" directionhint=\"false\" language=\"default\" poweredby=\"false\" maptypecontrol=\"true\" pancontrol=\"true\" zoomcontrol=\"true\" scalecontrol=\"true\" streetviewcontrol=\"true\" scrollwheelcontrol=\"false\" draggable=\"true\" tiltfourtyfive=\"false\" enablegeolocationmarker=\"false\" enablemarkerclustering=\"false\" addmarkermashup=\"false\" addmarkermashupbubble=\"false\" addmarkerlist=\" Buenos Aires{}1-default.png|Iguazu{}1-default.png|Bariloche{}1-default.png|Santiago{}1-default.png|\" bubbleautopan=\"true\" distanceunits=\"miles\" showbike=\"false\" showtraffic=\"false\" showpanoramio=\"false\"]</span>\n<h2>TEXT</h2>\n<address>*TEXT</address>\n

...除了更大(更多 html 文本)。

所以我现在不确定的是 HTML 字符是否没有被正确转义或者我是否在某处遗漏了一些东西。

一如既往,非常感谢您的帮助。 :)

最佳答案

试试这个:

    add_pkg_data = ("INSERT INTO wp_posts (post_author, post_date,"
"post_date_gmt, post_content, post_title, post_status,"
"comment_status, ping_status, post_name, "
"post_modified, post_modified_gmt, "
"post_parent, guid, menu_order, post_type, "
"comment_count) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, "
"%s, %s, %s, %s, %s, %s, %s)")

不确定最后的 %s 后面是否需要逗号。

关于Python 谷歌 API 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28187409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com