Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ValueError:不支持的格式字符';a';(0x61)在索引55处,带有URL字符串_Python_String_Url_Pymysql - Fatal编程技术网

Python ValueError:不支持的格式字符';a';(0x61)在索引55处,带有URL字符串

Python ValueError:不支持的格式字符';a';(0x61)在索引55处,带有URL字符串,python,string,url,pymysql,Python,String,Url,Pymysql,正在尝试使用以下代码将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/

正在尝试使用以下代码将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
被解释为格式化字符串,没有
格式。最好切换到新型格式,即使用
格式
方法而不是
%
运算符:

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)

我也试过了,效果不错。(
%%3A
而不是
%3A