Does not work command: http://username:password@domoticz ip:port

Subforum for general discussions. Do not dump your questions/problems here, but try to find the subforum where it belongs!

Moderators: leecollings, remb0

reza
Posts: 112
Joined: Tuesday 13 September 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Contact:

Does not work command: http://username:password@domoticz ip:port

Post by reza »

hi gays
i want use command http://username:password@domoticz ip:port
but does not work and when i enter this , open login page and request username and password.
also when i want send this command :
http://username:[email protected]: ... itchcmd=On
i have answer:
401 Unauthorized
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Does not work command: http://username:password@domoticz ip:port

Post by waltervl »

Do you have setting "Allow Basic-Auth authentication over plain HTTP (API only)" enabled in menu setup - Settings, tab security?

Edit: also some browsers do not allow to add user:password so to test you have to use something like curl or postman.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
mark.sellwood
Posts: 101
Joined: Tuesday 04 March 2014 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Surrey, UK
Contact:

Re: Does not work command: http://username:password@domoticz ip:port

Post by mark.sellwood »

I have also been trying to backup from a curl script with http://username:password@ipaddress/backupdatabase.php and get the same 401 Unauthorized
I have "Allow basic authorisation for HTTP" enabled in setup.
I know the username / password are good as I use them to log in
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Does not work command: http://username:password@domoticz ip:port

Post by waltervl »

mark.sellwood wrote: Wednesday 24 July 2024 0:22 I know the username / password are good as I use them to log in
And that user is an admin? Else it has no right to make a backup.
Also if you login from an IP in the trusted network range don't give user:password.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
mark.sellwood
Posts: 101
Joined: Tuesday 04 March 2014 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Surrey, UK
Contact:

Re: Does not work command: http://username:password@domoticz ip:port

Post by mark.sellwood »

Yes, the user is an Admin
If I add the Raspberry IP in as a Trusted Networks it works fine with no user:password
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
reza
Posts: 112
Joined: Tuesday 13 September 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Contact:

Re: Does not work command: http://username:password@domoticz ip:port

Post by reza »

waltervl wrote: Wednesday 24 July 2024 0:06 Do you have setting "Allow Basic-Auth authentication over plain HTTP (API only)" enabled in menu setup - Settings, tab security?

Edit: also some browsers do not allow to add user:password so to test you have to use something like curl or postman.

edit : i resolve it with curl. thank you
mark.sellwood
Posts: 101
Joined: Tuesday 04 March 2014 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Surrey, UK
Contact:

Re: Does not work command: http://username:password@domoticz ip:port

Post by mark.sellwood »

Could you please let me know the command you are using?
This is waht I gave & am getting the error/
/usr/bin/curl -k "https://user:password@IP_Address/backupdatabase.php" > /home/Mark/tmp/Backup.db
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
FlyingDomotic
Posts: 303
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Does not work command: http://username:password@domoticz ip:port

Post by FlyingDomotic »

Are there any ":", "@" or "/" in username and/or password?
mark.sellwood
Posts: 101
Joined: Tuesday 04 March 2014 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Surrey, UK
Contact:

Re: Does not work command: http://username:password@domoticz ip:port

Post by mark.sellwood »

No, just standard text
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
FlyingDomotic
Posts: 303
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Does not work command: http://username:password@domoticz ip:port

Post by FlyingDomotic »

mark.sellwood wrote: Wednesday 24 July 2024 8:39 Could you please let me know the command you are using?
This is waht I gave & am getting the error/
/usr/bin/curl -k "https://user:password@IP_Address/backupdatabase.php" > /home/Mark/tmp/Backup.db
It seems you're using https in curl, while using http in first message. Is this an error ?
mark.sellwood
Posts: 101
Joined: Tuesday 04 March 2014 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Surrey, UK
Contact:

Re: Does not work command: http://username:password@domoticz ip:port

Post by mark.sellwood »

My bad, this is what im using
/usr/bin/curl -s "http://user:password@IP_Address:8080/backupdatabase.php" > /home/Mark/tmp/Backup.db
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
FlyingDomotic
Posts: 303
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Does not work command: http://username:password@domoticz ip:port

Post by FlyingDomotic »

What's exact error message?

I assume you properly checked user and password, including lower/uppercase.
mark.sellwood
Posts: 101
Joined: Tuesday 04 March 2014 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Surrey, UK
Contact:

Re: Does not work command: http://username:password@domoticz ip:port

Post by mark.sellwood »

In the output file I have
<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Does not work command: http://username:password@domoticz ip:port

Post by waltervl »

For backup issue also see viewtopic.php?p=315818
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
FlyingDomotic
Posts: 303
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Does not work command: http://username:password@domoticz ip:port

Post by FlyingDomotic »

I found something...

I just tried the same (curl -k "http://username:password@ip:8080/backupdatabase.php" > Backup.db) with 2024.6 and 2020.2 with success.

I also tried without username and password (curl -k "http://ip:8080/backupdatabase.php" > Backup.db) and it also worked.

Both tests where done with the requesting machine in list of trusted networks in Security tab of Settings.

When removing it from list of trusted networks, I got the same error as you, with and without password (401 errors)

When trying API call (/json.htm?type=command&param=getversion), everything ran well.

Going back to wiki (RTFM), if found at https://www.domoticz.com/wiki/Security:

Code: Select all

Provide valid credentials via 'Basic-Auth' with each API request. Only accepted for API calls!
As your call is not an API call (not starting with /json.htm), you're not allowed to identify this way. You should either:
  • Put machine (or subnet) into trusted network list
  • As doc says: Retrieve an 'Access Token' (JWT Token) from the IAM server and provide this Bearer token with each request
First method worked for me, and I never tried second one...

Tip: carefully check that trusted networks are separated by a ";" as I had some surprises with a mistyped ","
mark.sellwood
Posts: 101
Joined: Tuesday 04 March 2014 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Surrey, UK
Contact:

Re: Does not work command: http://username:password@domoticz ip:port

Post by mark.sellwood »

Thanks for checking that our for me, I was coming to the same conclusion
ie to do a backup the User needs to be an Admin & the IP needs to be Trusted.
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
FlyingDomotic
Posts: 303
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Does not work command: http://username:password@domoticz ip:port

Post by FlyingDomotic »

... or write a small script, on machine having Domoticz, to generate backup locally and copy database to remote machine.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Does not work command: http://username:password@domoticz ip:port

Post by waltervl »

Or just enable the built in backup mechanism with automated hourly, daily and monthly backups.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
reza
Posts: 112
Joined: Tuesday 13 September 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Contact:

Re: Does not work command: http://username:password@domoticz ip:port

Post by reza »

mark.sellwood wrote: Wednesday 24 July 2024 8:39 Could you please let me know the command you are using?
This is waht I gave & am getting the error/
/usr/bin/curl -k "https://user:password@IP_Address/backupdatabase.php" > /home/Mark/tmp/Backup.db
in a .py file i use this code:

Code: Select all

import pycurl
from io import BytesIO
buffer = BytesIO()
curl = pycurl.Curl()
curl.setopt(pycurl.URL, 'http://username:[email protected]:8080/json.htm?type=command&param=switchlight&idx=1&switchcmd=On')
curl.setopt(pycurl.USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0")
curl.setopt(pycurl.WRITEDATA, buffer)
curl.perform()
curl.close()
mark.sellwood
Posts: 101
Joined: Tuesday 04 March 2014 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Surrey, UK
Contact:

Re: Does not work command: http://username:password@domoticz ip:port

Post by mark.sellwood »

Thanks for all your feedback.
I have now enabled the automated backups & once a day I copy the off to my NAS as a off line backup.
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest