Anrolosia/Shopping-List-with-Grocy

Grocy url access with name is not working

Closed this issue · 3 comments

I have grocy and Home Assistant in two containers. When I create the integration in home assistant, I get an invalid url error:

image

No error on home assistant logs so I believe it is a field validation, is it possible?

Inside Home Assistant Container its resolver the name correctly:

/config $ nslookup grocy
Server: 127.0.0.11
Address: 127.0.0.11#53

Non-authoritative answer:
Name: grocy
Address: 172.20.0.22

If I try to create the integration with the ip, it works perfectly fine.

image
image

The problem is that when I recreate the container for some reason, the fixed ip changes so I want to use name instead.

Hello @Tugado !
So, yeah, there is a validation on the url, should be a domain, or localhost, or an ip as you can see here:

def is_valid_url(url):
regex = re.compile(
r"^https?://" # http:// or https://
r"(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?|" # domain...
r"localhost|" # localhost...
r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})" # ...or ip
r"(?::\d+)?" # optional port
r"(?:/?|[/?]\S+)$",
re.IGNORECASE,
)

Could you play a bit with your HA container host_file to define a hostname which will redirect to your "grocy" container? like grocy.local grocy, or something like that?

Thanks! With the fixed IP Addres in host_file did the trick:

/config # echo "grocy grocy.local" >> /etc/hosts
/config # ping grocy.local
ping: bad address 'grocy.local'

/config # echo "172.20.0.22 grocy.local" >> /etc/hosts
/config # ping grocy.local -c1
PING grocy.local (172.20.0.22): 56 data bytes
64 bytes from 172.20.0.22: seq=0 ttl=64 time=1.193 ms

image

image

I'll seek to set up a definitive solution but it definitely works. Thanks for the help.

Nice :) So you could automate the creation of the container to add that line with the new ip address in your hosts file.
I will let the ticket here open if you need some help, let me know when we could close it.
Thanks