Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WARNING: Python-dotenv could not parse statement starting at line X #5

Open
LQss11 opened this issue Oct 21, 2022 · 1 comment
Open
Assignees

Comments

@LQss11
Copy link

LQss11 commented Oct 21, 2022

Let's say I have an env file like this:
docker.env

App__PathToFiles="C:\\Program Files\\SOMEPATH\\"
App__SomeOtherKey="Value"

and then passing it as an envfile in docker compose
docker-compose.yaml

version: '3.3'
services:
  app:
    image: alpine
    container_name: app
    tty: true
    env_file:
      - ./docker.env

Running docker-compose up with that config produces this error:

WARNING: Python-dotenv could not parse statement starting at line 1

This is because bashlash telling env to ignore the double quote which will break the structure of the config.

@dassump dassump self-assigned this Oct 23, 2022
@dassump
Copy link
Owner

dassump commented Oct 23, 2022

Hi @LQss11, I believe it is due to the unnecessary double quotes in the variable value.

I tested it with the same content and it didn't work either.

% cat > appsettings.json <<EOF
{
    "App": {
        "PathToFiles": "C:\\\\Program Files\\\\SOMEPATH\\\\",
        "SomeOtherKey": "Value"
    }
}
EOF
% dotnet-appsettings-env-darwin-arm64 -type docker | tee docker.env
App__PathToFiles="C:\\Program Files\\SOMEPATH\\"
App__SomeOtherKey="Value"
$ cat > docker-compose.yml <<EOF
version: '3.3'
services:
  app:
    image: alpine
    container_name: app
    tty: true
    env_file:
      - ./docker.env
EOF
% docker-compose up
unexpected character "\"" in variable name near "Value\"\n"

Removing the double quotes worked as expected.

% dotnet-appsettings-env-darwin-arm64 -type docker | tr -d \" | tee docker.env
App__PathToFiles=C:\\Program Files\\SOMEPATH\\
App__SomeOtherKey=Value
% docker-compose up -d
[+] Running 2/2
 ⠿ Network x_default  Created                    0.0s
 ⠿ Container app      Started                    0.2s
% docker exec -it app ash
/ # env
HOSTNAME=e733b8d2435c
App__SomeOtherKey=Value
SHLVL=1
HOME=/root
TERM=xterm
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/
App__PathToFiles=C:\\Program Files\\SOMEPATH\\

Can you remove the double quotes from your docker.env file and see if it will work?

Repository owner deleted a comment from erenakkaya Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants