布朗尼 UnicodeDecodeError: 'charmap'编解码器无法解码位置 2127 中的字节 0x9d:字符映射到<未定义>

发布于 2025-01-14 12:14:22 字数 920 浏览 4 评论 0原文

我尝试使用布朗尼编译我的合同,并收到以下错误:

File "C:\Users\muvis\AppData\Local\Programs\Python\Python310\lib\encodings\cp1252.py",第 23 行,解码 返回 codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError:“charmap”编解码器无法解码位置 2127 中的字节 0x9d:字符映射到

我想编译此合同:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";

contract compileError {
    string[13] unicodeValues = [
        "&#x20;",
        "&#x2588;",
        "&#x2665;",
        "&#xac;",
        "&#x2d8;",
        "&#x5e;",
        "&#x58;",
        "&#x25d4;",
        "&#x25d5;",
        "&#x273f;",
        "&#xca5;",
        "&#x25c9;",
        "&#x2686;" //" ", "█","♥","¬","˘","^","X","◔","◕","✿","ಥ","◉","⚆"
        //could think about adding flowers &#x2740; ->❀ but we have already flowers
    ];
}

I tried to compile my contract using brownie and got the following error:

File "C:\Users\muvis\AppData\Local\Programs\Python\Python310\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 2127: character maps to

I wanted to compile this contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";

contract compileError {
    string[13] unicodeValues = [
        " ",
        "█",
        "♥",
        "¬",
        "˘",
        "^",
        "X",
        "◔",
        "◕",
        "✿",
        "ಥ",
        "◉",
        "⚆" //" ", "█","♥","¬","˘","^","X","◔","◕","✿","ಥ","◉","⚆"
        //could think about adding flowers ❀ ->❀ but we have already flowers
    ];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

向地狱狂奔 2025-01-21 12:14:22

我找到了问题的答案(无法想象这个......):

即使 ascii 值在注释中,它也无法编译。如果我删除注释,那么代码看起来像这样:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";

contract compileError {
    string[13] unicodeValues = [
        " ",
        "█",
        "♥",
        "¬",
        "˘",
        "^",
        "X",
        "◔",
        "◕",
        "✿",
        "ಥ",
        "◉",
        "⚆"
    ];
}

它编译时没有任何错误。希望这对遇到同样问题的人有帮助

I found the answer for the problem (couldnt imagine this...):

even if the ascii values are in the comment it cant compile. If I remove the comments, so the code looks like this:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";

contract compileError {
    string[13] unicodeValues = [
        " ",
        "█",
        "♥",
        "¬",
        "˘",
        "^",
        "X",
        "◔",
        "◕",
        "✿",
        "ಥ",
        "◉",
        "⚆"
    ];
}

it compiles without any errors. Hope this is helpful for anyone with the same problem

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文