python Unicode编码错误:“charmap”编解码器无法对位置409中的字符“\u03a3”进行编码:字符Map到< undefined>

nwlls2ji  于 2023-03-16  发布在  Python
关注(0)|答案(1)|浏览(181)

我正在运行Python代码从JIRA中提取问题。此代码由Atlassian提供,他们正在使用JiraOne库。
在Config.Json文件中,我们有以下信息。

{
"user": "prince@example.com",
"password": "<APITOKEN_HERE>",
"url": "https://nexusfive.atlassian.net"
}

下面是我正在运行的Python代码。

from jiraone import LOGIN, issue_export
import json

file = "config.json"
config = json.load(open(file))
LOGIN(**config)

jql = "project in (AB, BC, IT, IP) order by created DESC"
issue_export(jql=jql)

我得到下面的错误消息,没有关于如何解决这个线索。
错误消息:

Downloading issue export in CSV format.
<Response [200]> OK ::downloading issues at page: 0 of 9
Traceback (most recent call last):

  File "C:\Users\User123\Desktop\PBI Files\Python Scripts\untitled10.py", line 12, in <module>
    issue_export(jql=jql)

  File "C:\Users\User123\Anaconda3\lib\site-packages\jiraone\reporting.py", line 2189, in export_issues
    file_writer(

  File "C:\Users\User123\Anaconda3\lib\site-packages\jiraone\reporting.py", line 3223, in file_writer
    f.write(content)

  File "C:\Users\User123\Anaconda3\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]

UnicodeEncodeError: 'charmap' codec can't encode character '\u03a3' in position 409: character maps to <undefined>
7gcisfzg

7gcisfzg1#

要遵循Prince Nyeche提供的修复程序,您必须执行以下操作:在文本编辑器中打开文件C:\Users\User123\Anaconda3\lib\site-packages\jiraone\reporting.py,转到第2189行,它应该如下所示:

file_writer(
            folder,
            file_name,
            content=issues.content.decode(encoding, errors=errors),
            mark="file",
            mode="w+",
        )

添加建议的编辑:

content=issues.content.decode('utf-8', errors="replace"),

保存文件。然后重试untitled10.py代码。

相关问题