我需要将测试用例中的日志插入到 postgresql 数据库中的表中。
我能够连接到数据库,但我不知道如何在表格中插入这一行结果,我尝试了以下但它不起作用
import logging
import psycopg2
from io import StringIO
from config import config
params = config()
conn = psycopg2.connect(**params)
print(conn)
curr = conn.cursor()
try:
if not hw.has_connection():
logging.error('Failure: Unable to reach websb! ==> '+ str(driver.find_element_by_xpath('//span[@jsselect="heading" and @jsvalues=".innerHTML:msg"]').text))
return
elif hw.is_websiteReachable():
logging.info("Success: website is reachable!")
curr.execute("""INSERT INTO db_name(logs) VALUES (%s)""", ("Success: website is reachable!"))
conn.commit()
except:
logging.error("Failure: Unable to reach website!")
return
我是这方面的初学者。我已经搜索过,但找不到明确的示例或指南。即使网站可以访问,上面的代码也会引发异常。对不起,如果我听起来很愚蠢。