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

huangapple go评论67阅读模式
英文:

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

问题

我正在运行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)

我收到以下错误消息,但不知道如何解决。
错误消息:

下载以CSV格式导出的问题。
<Response [200]> OK ::正在下载页面 0 的 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' 编解码器无法在位置 409 编码字符 'Σ':字符映射到 <undefined>
英文:

I am running Python code to pull the issues from JIRA. This code is provided by Atlassian and they are using JiraOne Library.

In the Config.Json file we have the following information.

{
&quot;user&quot;: &quot;prince@example.com&quot;,
&quot;password&quot;: &quot;&lt;APITOKEN_HERE&gt;&quot;,
&quot;url&quot;: &quot;https://nexusfive.atlassian.net&quot;
} 

Below is the Python code I am running.

from jiraone import LOGIN, issue_export
import json

file = &quot;config.json&quot;
config = json.load(open(file))
LOGIN(**config)

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

I am getting below error message and no clue on how to resolve this.

ERROR MESSAGE:

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

  File &quot;C:\Users\User123\Desktop\PBI Files\Python Scripts\untitled10.py&quot;, line 12, in &lt;module&gt;
    issue_export(jql=jql)

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

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

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

UnicodeEncodeError: &#39;charmap&#39; codec can&#39;t encode character &#39;\u03a3&#39; in position 409: character maps to &lt;undefined&gt;

答案1

得分: 0

按照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代码。

英文:

To follow the fix provided by Prince Nyeche you have to do the following. Open the file C:\Users\User123\Anaconda3\lib\site-packages\jiraone\reporting.py in your text editor. Go to line 2189. It should look like this:

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

Add the suggested edit:

content=issues.content.decode(&#39;utf-8&#39;, errors=&quot;replace&quot;),

Save your file. Then try your untitled10.py code again.

huangapple
  • 本文由 发表于 2023年3月15日 21:05:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75745139.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定