4

I have the Newman (postman cli) setup on AWS CodeBuild a few months ago, it was working perfectly. Then this error popped up from nowhere: error: Unknown encoding: latin1

Run the same command in local work perfectly.

Run the same command on inside a docker on AWS EC2 instance work perfectly.

It only fails on when running the AWS CodeBuild which is part of my AWS CodePipeline.

There is no any special character in the JSON file.

Here is my buildSpec for CodeBuild

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

Everything is working fine except - newman run APITesting.json -e env.json

It gave me an error for no sense: error: Unknown encoding: latin1

Even though I replaced APITesting.json with demo.json demo.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": "xxxx@gmail.com"
                    },
                ],
                "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": []
        }
    ]
}

It still complaining about the unknown encoding. I tried to use file -i or file -I to get the encoding of the file. All files have encoded in utf-8 or 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

Everything is running inside a Docker container, but I do not think it matters.

I searched all issues from Newman Github with no luck.

I also searched for everything related to Unknown encoding: latin1 in Google, StackOverflow, and AWS Discussion Forums with no result.

I already spent two days on it. Anyone have any clue?

Thank you so much!!!

Kun

Kun Su
  • 41
  • 3
  • I have same kind of issue on Jenkins. If found solution please mention me. Thanks – Mustafa Mohammadi Mar 05 '19 at 20:00
  • 2
    @Mustafa Mohammadi Yeah, I found a solution. So Newman has a feature that you can run the testingJSON file with an URL. ex: `newman run URL/APITesting.json` I hope it fix your issue too. – Kun Su Mar 06 '19 at 22:23

1 Answers1

0

If anyone runs into this, you can change UTF8 to UTF8 with BOM using the command below:

sed -i '1s/^\xEF\xBB\xBF//' your-file.json

This fixed the issue for us.

hellojebus
  • 3,267
  • 1
  • 21
  • 23