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

error parsing URLs for docker-compose style hostnames #153

Closed
dror-weiss opened this issue Apr 19, 2020 · 2 comments
Closed

error parsing URLs for docker-compose style hostnames #153

dror-weiss opened this issue Apr 19, 2020 · 2 comments

Comments

@dror-weiss
Copy link

Hello,

I have a parsing issue using env.url for docker-compose type URLs.

For example, if I have a service called vault that I want to reach from another service, I'm passing it an environment variable like so: VAULT_ADDRESS=http://vault:8200

This doesn't work:

from environs import Env

environment = Env(eager=False)
environment.read_env()


class Settings:
    vault_address: ParseResult = environment.url("VAULT_ADDRESS")


environment.seal()

Error:
environs.EnvValidationError: Environment variables invalid: {'VAULT_ADDRESS': ['Not a valid URL.']}

This works:

from environs import Env
from urllib.parse import ParseResult, urlparse

environment = Env(eager=False)

@environment.parser_for("url2")
def url2_parser(value):
    return urlparse(value)

environment.read_env()


class Settings:
    vault_address: ParseResult = environment.url2("VAULT_ADDRESS")


environment.seal()
  • Tested on 7.3.0 and 7.4.0
@eltonplima
Copy link

eltonplima commented Jun 18, 2020

You can try this:

env.url("VAULT_ADDRESS", require_tld=False)

Why? The answer is here

If you try to using an scheme different of http, https or ftp you can try this:

env.url("VAULT_ADDRESS", schemes={"my_custom_scheme"}, require_tld=False)

Why? The answer is here

@sloria
Copy link
Owner

sloria commented Oct 31, 2020

Closing for now since this is has more to do with how marshmallow validates URLs than with environs itself.

See @eltonplima's comment above for ways to work around this.

@sloria sloria closed this as completed Oct 31, 2020
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

3 participants