error parsing URLs for docker-compose style hostnames
dror-weiss opened this issue · comments
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
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.