gpt4 book ai didi

python - 值错误: unsupported format character 'a' (0x61) at index 55 with URL string

转载 作者:太空宇宙 更新时间:2023-11-03 15:03:13 53 4
gpt4 key购买 nike

尝试使用以下代码将 URL 和主机名发送到数据库:

def sendToDatabase(self, case, filename):
103 ext = os.path.splitext(filename)[1]
104 filenoext = filename.strip(ext)
105 url = "https://apses4859.ms.ds.uhc.com:10943/rest/download/C%3A/IBM/ISA5/ISA5/isa/cases/%s/%s-analyzer_ISA_PD/%s_Leak_Suspects/index.html" % (case, filename,filenoext)
106 cursor = connection.cursor()
107 m = re.search(r"([^.]*)", filename)
108 hostname = m.group(1)
109 query = "INSERT INTO StoryData (hostName, reportName) VALUES (%s, %s)"
110 cursor.execute(query , (hostname, url))
111 connection.commit()
112 cursor.close()

出于某种原因,它不喜欢 %3A 旁边的 A。我尝试添加额外的%,但仍然没有影响。不太明白为什么我会收到此错误。

最佳答案

%3A 被解释为格式化字符串,并且没有 A 格式。最好切换到新式格式,即。使用 format 方法而不是 % 运算符:

url = "https://apses4859.ms.ds.uhc.com:10943/rest/download/C%3A/IBM/ISA5/ISA5/isa/cases/{}/{}-analyzer_ISA_PD/{}_Leak_Suspects/index.html".format(case, filename,filenoext)

关于python - 值错误: unsupported format character 'a' (0x61) at index 55 with URL string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44890601/

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