简体   繁体   English

Python,Django:ValueError:索引3处不受支持的格式字符'('(0x28)

[英]Python, Django: ValueError: unsupported format character '(' (0x28) at index 3

Can somebody explain to me why this raises a ValueError? 有人可以向我解释为什么这会引发ValueError吗? (using Python 2.7) (使用Python 2.7)

from django.utils.translation import ugettext as _

...

template = _('► %(user)s, random text here @[%(friend_id)s] more random text ◄◄◄'.decode('utf-8')) % {'user': friend_profile.user.first_name, 'friend_id': user.id}

This is the error (sent by celery error email): 这是错误(通过芹菜错误电子邮件发送):

  File "/var/www/myapp/apps/app/tasks.py", line 54, in notify_friends_new_invite
    template=_('��� %(user)s, random text here @[%(friend_id)s] more random text ���������'.decode('utf-8')) % {'user': friend_profile.user.first_name, 'friend_id': user.id},
ValueError: unsupported format character '(' (0x28) at index 3

Check your message catalog entry. 检查您的消息目录条目。

The _(...) call replaces your unicode value with one from the message catalog (if available), and it is that message that throws this exception. _(...)调用将消息目录中的unicode值替换为一个(如果有),并且消息引发此异常。 Swapping the % and the preceding space would do this, for example: 交换%和前面的空格可以做到这一点,例如:

>>> '►% (user)s, random text here @[%(friend_id)s] more random text ◄◄◄'.decode('utf-8') % {'user':u'foo', 'friend_id': u'bar'}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: unsupported format character '(' (0x28) at index 3

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

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