2017-07-03 7 views
1

は、次のコードを使用してデータベースにURLやホスト名を送信しようとすると:とValueError:サポートされていない形式の文字「」(の0x61)インデックス55での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() 

それは次%にAを好きではないです何らかの理由で3A。私は余分な%を追加しようとしましたが、それはまだそれに影響しません。なぜこのエラーが出るのか分かりません。

+0

私も、それを試みたが、それは私のために[OK]を働きました。 ( '%3A'ではなく' %% 3A') – MarianD

答えて

1

%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) 
関連する問題