【问题标题】:ValueError: unsupported format character 'P' (0x50) at index 798ValueError:索引 798 处不支持的格式字符“P”(0x50)
【发布时间】:2019-09-15 15:22:45
【问题描述】:

我正在尝试通过 Python 使用 SQLQuery 执行查询以搜索数据库中的 4 个表。每次我尝试将以下字符串作为查询执行时,都会出现上述错误。

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)

我验证了各种论坛,但无法解决这个问题,如果我删除 maxDate 和 CurrentTime 参数,相同的查询会起作用。我在这里错过了什么。

【问题讨论】:

    标签: python mysql mysql-python


    【解决方案1】:

    看来你的 % 放错地方了

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

    尝试删除

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

    或者逃跑

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-28
      • 1970-01-01
      • 2020-08-25
      • 2017-12-07
      • 2023-03-29
      • 1970-01-01
      • 2012-07-26
      相关资源
      最近更新 更多