Restful command changes url characters

Hey there,

I have a problem I cannot solve on my own it seems. I am new to the forum but not to HA. However, I am not a power user like most knowledgable guys and girls here.

I like to update the IP on my subdomains via a dyndns update url my provider offers for this. I read through the forum and found some guys doing the same already using the restful command. Hence, I tried it in browser to make sure everything works fine, which it did.

I then set up the rest_command in my config.yaml and the service is available after reboot but returns a 403 status (forbidden, wrong credentials). I checked in the log why his happens and found the error. The password I send with the url contains special characters for examle “}”. However the character is not send as is but as “%7D”, which causes the transmitted password to be false. I read up on the forum and the docs, but couldnt find what to or how to do. I am sure the problem is the character set used, but I dont know how to change it. I tried content_type but couldnt get it to work.

Any help from all of you or a pointer to a ressource is greatly appreciated. Thanks!
André

  1. Show us code :wink:
  2. See 1). Do you use username/ password from the rest_command?

Hey there,

first of all thanks for getting back to me! Secondly, I am sorry for not posting the code earlier, I was on my phone and it was a bit difficult to get the code in here.

I checked the forums further and found a method by another user that uses a script. However, the error remains.

The following is the definition of the rest_command

restcommands.yaml (which is included in the configuration.yaml)

subdomainddnsmydomaintld:
  url:  "{{ ddns_url }}"
  method: get

and the scripts.yaml (which is included in the configuration.yaml)

xxxddns:
  sequence:
      - variables:
            - ddns_domain: !secret xxx_login
            - ddns_pass: !secret xxx_pass
            - full_dns_url: https://cloudpit.io/dynDns/update?login={{ddns_domain}}&password={{ddns_pass}}
      - service: rest_command.subdomainddnsmydomaintld
        data: '{{ full_ddns_url }}'

The problem is, that the password contains a number of characters that are not send as is but “transformed” (seems utf-8 encoding does this transformation for “}” to "%7D). I am really not an expert on this and the solution is for sure simple, so I hope I dont offend anyone with such a simple problem.

As an example assume password is defined in the secrets.yaml as

ddns_pass: }abcdefg]xyz

then the url send via the script/rest_command service is

https://cloudpit.io/dynDns/update?login=domain.tld&password=%7Dabcdefg%5Dxyz

instead of

https://cloudpit.io/dynDns/update?login=domain.tld&password=}abcdefg]xyz

which the dyndns update server at cloudpit.io identifies as false and responds with a status code 403 due to invalid credentials because the password is wrong.

I just dont know how to tell the rest_command, how to send the password string as is. I guess this can be done using the content_type variable set to a proper value when configuring the rest_command.

I really hope it is clear now what I want to achieve and what the error is.

Thank you again for any help you you can offer. It is very much appreciated.
A.

Hello guys.

I have similar issue after some last HA update. I’m using REST to get temperature using url:

http://bero.local/getregister.cgi?1@temp&1@rh

the problem is that ‘@’ character is replaced by its ‘urlencode’ form ‘%40’ before request is send to the device. Due to that fact I’m not able to read proper values from the device. I think it is related to urllib.parse.quote(string, safe='/', encoding=None, errors=None) function. Please find below log extract with wrongly encoded entry (should be 1@temp not 1%40temp). How to overcome this? I need to mark ‘@’ character as safe char.

[homeassistant.components.rest.sensor] JSON converted from XML: {"cmd":{"@status":"ok","device":{"@id":"0","reg":{"@vid":"0","@tid":"1%40temp","@status":"not_found"}}}}