几个月前,我在AWS CodeBuild上安装了Newman(postman cli),它运行良好。然后从任何地方弹出此错误:error: Unknown encoding: latin1
在本地工作中完美运行同一命令。
在AWS EC2实例上的docker内部运行相同的命令非常正常。
仅在运行AWS CodePipeline的一部分的AWS CodeBuild时失败。
JSON文件中没有任何特殊字符。
这是我的CodeBuild的buildSpec
version: 0.2
env:
variables:
AWS_HOST : "https://api.aws.com/demo-testing"
phases:
pre_build:
commands:
- npm install newman --global
build:
commands:
- newman run APITesting.json -e env.json --bail
一切正常,除了- newman run APITesting.json -e env.json
它毫无意义地给了我一个错误:error: Unknown encoding: latin1
即使我用demo.json替换了APITesting.jsondemo.json:
{
"info": {
"_postman_id": "5bc2766f-eefc-48f2-a778-f05b2b2465ef",
"name": "A",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "GetMyProfile",
"event": [
{
"listen": "test",
"script": {
"id": "1b46d302-7014-4c09-bac9-751d2cec959d",
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});"
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"id": "f9a5dc64-33ab-42b1-9efa-f0a3614db340",
"exec": [
""
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "noauth"
},
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "user",
"value": "xxxx"
},
{
"key": "email",
"value": "[email protected]"
},
],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "https://api.aws.com/demo-testing/api/profile",
"protocol": "https",
"host": [
"api",
"aws",
"com"
],
"path": [
"demo-testing",
"api",
"profile"
]
}
},
"response": []
}
]
}
它仍然抱怨未知的编码。我试图使用file -i or file -I
来获取文件的编码。所有文件均已编码为utf-8
或us-ascii
[Container] 2019/02/27 06:26:34 Running command file -i APITesting.json
APITesting.json: text/plain; charset=utf-8
[Container] 2019/02/27 06:26:34 Running command file -i env.json
env.json: text/plain; charset=us-ascii
[Container] 2019/02/27 06:26:34 Running command file -i demo.json
env.json: text/plain; charset=utf-8
一切都在Docker容器中运行,但是我认为这并不重要。
我很幸运地从Newman Github搜索了所有问题。
我还搜索了与未知编码有关的所有内容:Google,StackOverflow和AWS讨论论坛中的latin1,没有结果。
我已经花了两天时间。有人知道吗?
非常感谢你!
坤
如果有人遇到此问题,您可以使用以下命令将带有BOM的UTF8更改为UTF8:
sed -i '1s/^\xEF\xBB\xBF//' your-file.json
这为我们解决了这个问题。