python 2.7 - TypeError: unsupported operand type(s) for %: 'long' and 'str' -


इस कोड के साथ:

  current_time = time.localtime () time_now = time.strftime ('% H:% M:% S', current_time) cursor.execute ("SUBSCRIPTION_DETAILS से * चुनें * अलर्ट_time = '% s'")% time_now  

मुझे त्रुटि मिलती है:

 % के लिए असमर्थित ऑपरेंप प्रकार (s): long and str  

प्रकार of अलर्ट_टाइम Varchar है

आपने अपना %

खो दिया है आप अब कर रहे हैं:

  कर्सर.असेक्यूट ("[स्निप]")% time_now  

इसलिए आप time_now < / Code> cursor.execute

के परिणाम पर आप स्ट्रिंग के साथ % का उपयोग कर सकते हैं, जैसे:

< पूर्व> कर्सर। एक्सक्यूट ("[स्निप]"% time_now)

लेकिन ऐसा मत करो, आपको उपयोग करना चाहिए:

  कर्सर। Execute ("चुनें SUBSCRIPTION_DETAILS से * जहां Alert_time =% s", (टीआई  

ध्यान दें कि हम यहां % ऑपरेटर का उपयोग करने के बजाय दूसरे पैरामीटर के रूप में समय-समय गुजरते हैं। यह सुनिश्चित करता है कि एसक्यूएल इंजेक्शन के हमलों को रोकने के लिए क्वेरी ठीक से साफ कर दी गई है।

दूसरा असल में एक ट्यूपल है यह सुनिश्चित करने के लिए , अनुगामी (कुछ हद तक बदसूरत)। < / P>


Comments

Popular posts from this blog

javascript - How to use the code plugin with popcornjs -

Python, converting png to gif using ImageMagick -

android layout hide/show views -