gpt4 book ai didi

python - 统一码编码错误 : 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)?

转载 作者:行者123 更新时间:2023-12-05 09:21:13 27 4
gpt4 key购买 nike

我有这样的列表:

l=[u'\u0634\u0628\u06a9\u0647 \u0645\u062d\u0628\u0627\u0646 \u0627\u0647\u0644 \u0628\u06cc\u062a \u0639\u0644\u06cc\u0647\u0645 \u0627\u0644\u0633\u0644\u0627\u0645', u'\u0622\u062e\u0631\u06cc\u0646 \u0641\u0639\u0627\u0644\u06cc\u062a \u0647\u0627 \u062f\u0631 \u0647\u0627\u062f\u06cc \u0646\u062a \u0628\u0631\u06af\u0631\u0641\u062a\u0647 \u0627\u0632 \u0646\u0627\u0645 \u0627\u0645\u0627\u0645 \u0646\u0642\u06cc \u0639\u0644\u06cc\u0647 \u0627\u0644\u0633\u0644\u0627\u0645', u'\u0648\u0631\u0648\u062f', u'\u0622\u062e\u0631\u06cc\u0646 \u0622\u0646\u0644\u0627\u06cc\u0646 \u0647\u0627', u'\u06a9\u0627\u0631\u0628\u0631\u0627\u0646 \u0641\u0639\u0627\u0644', u'\u06af\u0631\u0648\u0647 \u0647\u0627\u06cc \u0641\u0639\u0627\u0644', u'\u0645\u062d\u0628\u0648\u0628\u062a\u0631\u06cc\u0646 \u0628\u0631\u0686\u0633\u0628 \u0647\u0627', u'\u0628\u0647 \u067e\u0627\u062a\u0648\u0642 \u0627\u06cc\u0646\u062a\u0631\u0646\u062a\u06cc \u0645\u062d\u0628\u0627\u0646 \u0627\u0647\u0644 \u0628\u06cc\u062a \u0639\u0644\u06cc\u0647\u0645 \u0627\u0644\u0633\u0644\u0627\u0645 \u062e\u0648\u0634 \u0622\u0645\u062f\u06cc\u062f', u'\u06cc\u0627 \u062d\u0633\u06cc\u0646(\u0639)...\n\n\u0645\u06cc \u0628\u0631\u0645 \u06cc\u06a9 \u0631\u0648\u0632 \u0627\u0632 \u0627\u0635\u0644\u06cc\u062a\u0645\n\u0622\u062e\u0631 \u0627\u0632 \u0639\u0634\u0642\u062a \u0639\u0631\u0627\u0642\u06cc \u0645\u06cc \u0634\u0648\u0645..', u'#\u0627\u0644\u0644\u0651\u0647\u0640\u064f\u0640\u0640\u0645\u0651\u064e \u0635\u064e\u0640\u0644\u0651\u0650 \u0639\u064e\u0644\u0640\u06cc #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0622\u0644\u0650 #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0639\u064e\u062c\u0651\u0650\u0640\u0640\u0644\u0652 \u0641\u0640\u064e\u0640\u064e\u0631\u064e\u062c\u064e\u0640\u0647\u064f\u0645 \n#\u0627\u0644\u0644\u0651\u0647\u0640\u064f\u0640\u0640\u0645\u0651\u064e \u0635\u064e\u0640\u0644\u0651\u0650 \u0639\u064e\u0644\u0640\u06cc #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0622\u0644\u0650 #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0639\u064e\u062c\u0651\u0650\u0640\u0640\u0644\u0652 \u0641\u0640\u064e\u0640\u064e\u0631\u064e\u062c\u064e\u0640\u0647\u064f\u0645 \n#\u0627\u0644\u0644\u0651\u0647\u0640\u064f\u0640\u0640\u0645\u0651\u064e \u0635\u064e\u0640\u0644\u0651\u0650 \u0639\u064e\u0644\u0640\u06cc #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0622\u0644\u0650 #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0639\u064e\u062c\u0651\u0650\u0640\u0640\u0644\u0652 \u0641\u0640\u064e\u0640\u064e\u0631\u064e\u062c\u064e\u0640\u0647\u064f\u0645', u'#\u0627\u0644\u0644\u0651\u0647\u0640\u064f\u0640\u0640\u0645\u0651\u064e \u0635\u064e\u0640\u0644\u0651\u0650 \u0639\u064e\u0644\u0640\u06cc #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0622\u0644\u0650 #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0639\u064e\u062c\u0651\u0650\u0640\u0640\u0644\u0652 \u0641\u0640\u064e\u0640\u064e\u0631\u064e\u062c\u064e\u0640\u0647\u064f\u0645\n#\u0627\u0644\u0644\u0651\u0647\u0640\u064f\u0640\u0640\u0645\u0651\u064e \u0635\u064e\u0640\u0644\u0651\u0650 \u0639\u064e\u0644\u0640\u06cc #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0622\u0644\u0650 #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0639\u064e\u062c\u0651\u0650\u0640\u0640\u0644\u0652 \u0641\u0640\u064e\u0640\u064e\u0631\u064e\u062c\u064e\u0640\u0647\u064f\u0645\n#\u0627\u0644\u0644\u0651\u0647\u0640\u064f\u0640\u0640\u0645\u0651\u064e \u0635\u064e\u0640\u0644\u0651\u0650 \u0639\u064e\u0644\u0640\u06cc #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0622\u0644\u0650 #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0639\u064e\u062c\u0651\u0650\u0640\u0640\u0644\u0652 \u0641\u0640\u064e\u0640\u064e\u0631\u064e\u062c\u064e\u0640\u0647\u064f\u0645', u'#\u0627\u0644\u0644\u0651\u0647\u0640\u064f\u0640\u0640\u0645\u0651\u064e \u0635\u064e\u0640\u0644\u0651\u0650 \u0639\u064e\u0644\u0640\u06cc #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0622\u0644\u0650 #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0639\u064e\u062c\u0651\u0650\u0640\u0640\u0644\u0652 \u0641\u0640\u064e\u0640\u064e\u0631\u064e\u062c\u064e\u0640\u0647\u064f\u0645 \n#\u0627\u0644\u0644\u0651\u0647\u0640\u064f\u0640\u0640\u0645\u0651\u064e \u0635\u064e\u0640\u0644\u0651\u0650 \u0639\u064e\u0644\u0640\u06cc #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0622\u0644\u0650 #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0639\u064e\u062c\u0651\u0650\u0640\u0640\u0644\u0652 \u0641\u0640\u064e\u0640\u064e\u0631\u064e\u062c\u064e\u0640\u0647\u064f\u0645 \n#\u0627\u0644\u0644\u0651\u0647\u0640\u064f\u0640\u0640\u0645\u0651\u064e \u0635\u064e\u0640\u0644\u0651\u0650 \u0639\u064e\u0644\u0640\u06cc #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0622\u0644\u0650 #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0639\u064e\u062c\u0651\u0650\u0640\u0640\u0644\u0652 \u0641\u0640\u064e\u0640\u064e\u0631\u064e\u062c\u064e\u0640\u0647\u064f\u0645', u'\u062f\u062e\u062a\u0631\u0627\u0646 \u0645\u0648\u0645\u0646 \u0633\u0647 \u0648\u06cc\u0698\u06af\u06cc \u062f\u0627\u0631\u0646\u062f:\n      \u0645\u062a\u06a9\u0628\u0631\u060c\u0628\u062e\u06cc\u0644 \u0648 \u062a\u0631\u0633\u0648 \u0647\u0633\u062a\u0646\u062f!\n\n \ufe8d\u0645\u06cc\u0631\u0627\u0644\u0645\u0624\u0645\u0646\u06cc\u0646 \ufecb\ufee0\ufbfd (\u0639\u0644\u06cc\u0647 \u0627\u0644\u0633\u0644\u0627\u0645) \ufee3\ufbfd \ufed3\ufeae\ufee3\ufe8e\ufbfe\ufee8\ufeaa:\n\n\ufeaf\ufee7\ufe8e\ufee5 \ufeed \ufea9\ufea7\ufe98\ufeae\ufe8d\ufee5 \ufee3\ufeee\ufee3\ufee6 \ufe91\ufe8e\ufbfe\ufeaa \ufe8d\ufbfe\ufee6 \ufeb3\ufeea \ufebb\ufed4\ufe96 \ufead\ufe8d \ufb90\ufeea \ufe91\ufeae\ufe8d\ufbfc \ufee3\ufeae\ufea9\ufe8d\ufee5 \ufe91\ufeaa \ufe8d\ufeb3\ufe96\u060c\ufea9\ufe8d\ufeb7\ufe98\ufeea \ufe91\ufe8e\ufeb7\ufee8\ufeaa.\n\n\ufe8d\ufeed\ufedd \ufe8d\ufbfe\ufee8\ufb91\ufeea \ufee3\ufe98\ufb91\ufe92\ufeae \ufe91\ufe8e\ufeb7\ufee8\ufeaa.\n\n\ufea9\ufbfe\ufb95\ufeae \ufe8d\ufbfe\ufee8\ufb91\ufeea \ufe97\ufeae\ufeb3\ufeee \ufe91\ufe8e\ufeb7\ufee8\ufeaa.\n\n\ufeed \ufeb3\ufeee\ufee1 \ufeeb\ufee2 \ufe8d\ufbfe\ufee8\ufb91\ufeea \ufe91\ufea8\ufbff\ufede \ufe91\ufe8e\ufeb7\ufee8\ufeaa.\n\n\n\ufe8d\ufee3\ufe8e \ufe8d\ufbfe\ufee8\ufb91\ufeea \ufee3\ufe98\ufb91\ufe92\ufeae \ufe91\ufe8e\ufeb7\ufee8\ufeaa \ufbfe\ufecc\ufee8\ufbfd \ufea9\ufead \ufee3\ufed8\ufe8e\ufe91\ufede \ufee7\ufe8e\ufee3\ufea4\ufeae\ufee1 \ufe91\ufe8e \ufed7\ufe8e\ufec3\ufecc\ufbff\ufe96 \ufeed \ufe97\ufeae\ufeb7\ufeae\ufeed\ufbfe\ufbfd \ufebb\ufea4\ufe92\ufe96 \ufb90\ufee8\ufee8\ufeaa \ufeed \ufe8d\ufeaf \ufea3\ufeae\ufed1 \ufeaf\ufea9\ufee5 \ufe91\ufe8e \ufecb\ufeb8\ufeee\ufee9 \ufeed \ufe97\ufe92\ufeb4\ufee2 \ufb90\ufeea \ufea9\ufbfe\ufb95\ufeae\ufe8d\ufee5 \ufead\ufe8d \ufe97\ufea4\ufeae\ufbfe\ufb8f \ufee3\ufbff\ufb91\ufee8\ufeaa \ufe91\ufb59\ufeae\ufeeb\ufbff\ufeb0\ufee7\ufeaa.\n\n\ufee3\ufee8\ufec8\ufeee\ufead \ufe8d\ufeaf \ufe97\ufeae\ufeb1 \ufeeb\ufee2 \ufe97\ufeae\ufeb1 \ufe8d\ufeaf \ufe97\ufee8\ufeec\ufe8e \ufe91\ufeee\ufea9\ufee5 \ufeed \ufe97\ufee8\ufeec\ufe8e \ufee3\ufe8e\ufee7\ufeaa\ufee5 \ufe91\ufe8e \ufeb7\ufea8\ufebc\ufbfd \ufe8d\ufeb3\ufe96 \ufb90\ufeea \ufecb\ufee8\ufeee\ufe8d\ufee5 \ufee7\ufe8e\ufee3\ufea4\ufeae\ufee1 \ufea9\ufe8d\ufead\ufea9.\n\n\ufe8d\ufee3\ufe8e \ufe8d\ufbfe\ufee8\ufb91\ufeea \ufe91\ufea8\ufbff\ufede \ufe91\ufe8e\ufeb7\ufeaa \ufbfe\ufecc\ufee8\ufbfd \ufea9\ufead \ufea3\ufed4\ufec6 \ufee3\ufe8e\u0644 \ufea7\ufeee\ufea9 \ufeed \ufeb7\ufeee\ufeeb\ufeae\u060c\ufb90\ufee4\ufe8e\ufedd \ufea9\ufed7\ufe96 \ufeed \ufeed\ufeb3\ufeee\ufe8d\ufeb1 \ufead\ufe8d \ufe91\ufeea \ufea7\ufeae\ufe9d \ufea9\ufeeb\ufeaa \ufeed \ufe8d\ufee3\ufe8e\ufee7\ufe96 \ufea9\ufe8d\ufead \ufe8d\ufee3\ufeee\ufe8d\ufedd \ufeeb\ufee4\ufeb4\ufeae \ufea7\ufeee\ufea9 \ufe91\ufe8e\ufeb7\ufeaa.\n\n\ufee7\ufeec\ufe9e \ufe8d\ufedf\ufe92\ufefc\u200c\ufecf\ufeea \ufed3\ufbff\ufebe \ufe8d\ufefb\u200c\ufeb3\ufefc\u200c\u0645 \ufea3\ufb91\ufee4\ufe96266\u060c\ufeb91191', u'#\u0627\u0644\u0644\u0651\u0647\u0640\u064f\u0640\u0640\u0645\u0651\u064e \u0635\u064e\u0640\u0644\u0651\u0650 \u0639\u064e\u0644\u0640\u06cc #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0622\u0644\u0650 #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0639\u064e\u062c\u0651\u0650\u0640\u0640\u0644\u0652 \u0641\u0640\u064e\u0640\u064e\u0631\u064e\u062c\u064e\u0640\u0647\u064f\u0645', u'#\u0627\u0644\u0644\u0651\u0647\u0640\u064f\u0640\u0640\u0645\u0651\u064e \u0635\u064e\u0640\u0644\u0651\u0650 \u0639\u064e\u0644\u0640\u06cc #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0622\u0644\u0650 #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0639\u064e\u062c\u0651\u0650\u0640\u0640\u0644\u0652 \u0641\u0640\u064e\u0640\u064e\u0631\u064e\u062c\u064e\u0640\u0647\u064f\u0645', u'#\u0627\u0644\u0644\u0651\u0647\u0640\u064f\u0640\u0640\u0645\u0651\u064e \u0635\u064e\u0640\u0644\u0651\u0650 \u0639\u064e\u0644\u0640\u06cc #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0622\u0644\u0650 #\u0645\u064f\u062d\u064e\u0640\u0640\u0645\u0651\u064e\u062f \u0648\u064e\u0639\u064e\u062c\u0651\u0650\u0640\u0640\u0644\u0652 \u0641\u0640\u064e\u0640\u064e\u0631\u064e\u062c\u064e\u0640\u0647\u064f\u0645 \n\n\u0627\u0644\u0644\u0647\u0645 \u0639\u062c\u0644 \u0644\u0648\u0644\u06cc\u06a9 \u0627\u0644\u0641\u0631\u062c', u'', u'', u'.........', u'\u0627\u0646 \u0634\u0627\u0621\u0627\u0644\u0644\u0647 \u0642\u0633\u0645\u062a \u0647\u0645\u0647 \u0639\u0627\u0634\u0642\u0627\u0646 \u0627\u0632 \u062c\u0645\u0644\u0647 \u0634\u0645\u0627 \u0628\u0634\u0647.', u'\u0645\u0645\u0646\u0648\u0646 \u0627\u0646 \u0634\u0627\u0621\u0627\u0644\u0644\u0647', u'++++++++', u'\u0639\u06a9\u0633 \u0648 \u0645\u062a\u0646 \u0641\u0648\u0642 \u0627\u0644\u0639\u0627\u062f\u0647 \u0633 \n\r\n\u062e\u0631\u0627\u0628\u0647 \u0686\u0631\u0627\u063a\u0648\u0646\u0647 \u0627\u0645\u0634\u0628 ...', u'', u'\u0627\u0644\u0633\u0644\u0627\u0645 \u0639\u0644\u06cc\u06a9 \u06cc\u0627 \u0633\u06cc\u062f \u0627\u0644\u0633\u0627\u062f\u0627\u062a \u0627\u0644\u0627\u0639\u0627\u0638\u0645 #\u0627\u062d\u0645\u062f-\u0628\u0646-\u0645\u0648\u0633\u06cc-\u0627\u0644\u06a9\u0627\u0638\u0645', u'\u0627\u062e\u0628\u0627\u0631 \u0631\u0633\u0627\u0646\u0647\u200c\u0647\u0627']

我想将其转换为 utf-8 并查看我的数据。所以我试过了:

a=u', '.join(x.decode('unicode-escape') for x in l)

但是出现如下错误:

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)

问题是什么,我该如何解决?

我的list2没有问题:

l2=['\u0648', '\u062f\u0633\u062a\u0648\u0631', '\u062a\u0648' ,'\u0631\u0627 \u0633\u0628\u06a9' ,'\u0634\u0645\u0627\u0631\u0645!\n\n\u0648']
print u', '.join(x.decode('unicode-escape') for x in l2)
و, دستور, تو, را سبک, شمارم!

و

最佳答案

您已经有了 unicode 对象,无需编码或解码即可打印它们

Python3.5

>>> a=', '.join(l)
>>> a
'شبکه محبان اهل بیت علیهم السلام, آخرین فعالیت ها در هادی نت برگرفته از نام امام نقی علیه السلام, ورود, آخاتوق اینترنتی محبان اهل بیت علیهم السلام خو'

Python2.7.10

>>> l=",".join(l)
>>> print l
شبکه محبان اهل بیت علیهم السلام,آخرین فعالیت ها در هادی نت برگرفته از نام امام نقی علیه السلام,ور

关于python - 统一码编码错误 : 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33650417/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com