简体   繁体   English

索引79处不支持的格式字符'O'(0x4f)

[英]unsupported format character 'O' (0x4f) at index 79

I'm getting the below error while executing a query using Psycopg2 module. 使用Psycopg2模块执行查询时出现以下错误。 I have executed the same query in PgAdmin 4, and it is working fine and giving me results .The error occurs when i execute it via Python. 我已经在PgAdmin 4中执行了相同的查询,并且运行良好,并且给了我结果 。当我通过Python执行该错误时会发生错误。

Can anyone suggest me how to resolve this? 谁能建议我如何解决这个问题?

below is the code: 下面是代码:

for new_ticket in zenpy_client.search(type='ticket', status='open',requester='je.rr.y@gmail.com'):
    #new_ticket.assignee = modified_user
     #print(new_ticket.requester.email)

     psql_command=""" WITH CTE AS (select cast(origin as text) as origin, MAX(case when name like '%OUT%' THEN name else ''end) as out_ref
                                    , MAX(case when name like '%PICK%' THEN name else ''end) as pick_ref
                                    , MAX(case when name like '%PICK%' THEN state else ''end) as pick_state
                                        , MAX(case when name like '%OUT%' THEN state else ''end) as out_state
                     from dl_odoo.stock_picking 
                     GROUP BY origin)
               select o.customer_email,o.order_number,o.order_state_1,o.order_state_2,o.order_subtotal_net_after_discount as revenue
                 ,created_at_order,c.out_ref as reference,o.payment_method,c.pick_ref,c.pick_state,c.out_ref,c.out_state
               from ol.orders o 
                       LEFT JOIN CTE c ON c.origin=o.order_number 
                   where
                       customer_email='%s' order by o.created_at_order desc limit 3
                   ;"""
     try:
         s=''
         print(new_ticket.requester.email)
         print(psql_command)
         try:
             psql_cursor.execute(psql_command %new_ticket.requester.email)
         except (Exception, psycopg2.Error) as error:
             print ("ssss")
             print (error)

You need to escape the percent signs in the string. 您需要转义字符串中的百分号。 Python is interpreting them as if they are printf-like format specifiers. Python将它们解释为好像是类似于printf的格式说明符。 Replace each % with %% and it should work. 用%%替换每个%,它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 %d由python和附加ValueError:索引2处不支持的格式字符&#39;O&#39;(0x4f) - %d by python and addition ValueError: unsupported format character 'O' (0x4f) at index 2 ValueError:索引79处不支持的格式字符&#39;a&#39;(0x61) - ValueError: unsupported format character 'a' (0x61) at index 79 Python,Django:ValueError:索引3处不受支持的格式字符&#39;(&#39;(0x28) - Python, Django: ValueError: unsupported format character '(' (0x28) at index 3 Python:ValueError:索引1处不支持的格式字符&#39;&#39;&#39;(0x27) - Python: ValueError: unsupported format character ''' (0x27) at index 1 ValueError:索引 650 处不支持的格式字符 &#39;w&#39; (0x77) - ValueError: unsupported format character 'w' (0x77) at index 650 ValueError:索引798处不支持的格式字符&#39;P&#39;(0x50) - ValueError: unsupported format character 'P' (0x50) at index 798 ValueError:不支持的格式字符“!” (0x21) 在索引 2235 - ValueError: unsupported format character '!' (0x21) at index 2235 ValueError: 索引 21 处不支持的格式字符 ')' (0x29) - ValueError: unsupported format character ')' (0x29) at index 21 ValueError:索引处不支持的格式字符&#39;{&#39;(0x7b) - ValueError: unsupported format character '{' (0x7b) at index ValueError:索引3处不支持的格式字符&#39;&lt;&#39;(0x3c) - ValueError: unsupported format character '<' (0x3c) at index 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM