[英]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.