简体   繁体   中英

ValueError: unsupported format character 'P' (0x50) at index 798

I'm trying to execute a query to search 4 tables in a database using SQLQuery through Python. Every time I try and execute the following string as a query, it gives me the above error.

data2 = pd.read_sql("SELECT DateTime, vManagedEntity.DisplayName, vPerformanceRule.ObjectName, vPerformanceRule.CounterName, vPerformanceRuleInstance.InstanceName, SampleCount,AverageValue, MinValue, MaxValue FROM Perf.vPerfHourly INNER JOIN vPerformanceRuleInstance ON Perf.vPerfHourly.PerformanceRuleInstanceRowId =vPerformanceRuleInstance.PerformanceRuleInstanceRowId INNER JOIN vPerformanceRule ON vPerformanceRuleInstance.RuleRowId = vPerformanceRule.RuleRowId INNER JOIN vRelationship ON Perf.vPerfHourly.ManagedEntityRowId = vRelationship.TargetManagedEntityRowId INNER JOIN vManagedEntity ON vRelationship.SourceManagedEntityRowId =vManagedEntity.ManagedEntityRowId WHERE vPerformanceRule.ObjectName in ('Processor', 'Memory', 'Network Adapter', 'System', 'LogicalDisk') AND vPerformanceRule.CounterName in ('% Processor Time', 'Available Mbytes', 'Pages/sec', 'PercentBandwidthUsedTotal', 'Bytes Total/sec', 'Processor Queue Length', '% Free Space', 'Avg. Disk sec/Transfer', 'Current Disk Queue Length') AND LEFT(DisplayName,7) not in ('Active ', 'AD Doma', 'Windows ') AND (DateTime BETWEEN '%s' and '%s')" % (maxDate,currentTime),cnxn)

I verified various forums but couldn't able to solve this, the Same query works if I remove maxDate and CurrentTime parameters. what am I missing here.

Seems you have a % in wrong place

 ....AND vPerformanceRule.CounterName in ('% Processor Time', 'Available Mbytes',.....

try remove

....AND vPerformanceRule.CounterName in ('Processor Time', 'Available Mbytes', ....

or escape

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM