-
Notifications
You must be signed in to change notification settings - Fork 43
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
Unable to connect to a UDM Pro with this library #12
Comments
Historically by default the Unifi controller is on port 8443, not port 443. If you are running a CloudKey or similar then there is a UI on 443, but it redirects you to port 8443 for the Unifi Network interface and port 7443 for the Unifi Protect interface. Try the using port 8443 and see if that fixes it (or just don't specify the That said, even if that fixes it the error message is unhelpful; I'll put in some more informative error handling when I have some time. |
Thank you, Nickovs. 8443 isn't working for me either. I'm going to try digging into your code and see if I can figure out what's going on. If I find a solution, I'll certainly contribute. |
Based on the stack backtrace, it looks like the crash is happening because whatever the server is sending back can not be decoded as a JSON payload even though the HTTP request returned an If you are up for trying to debug this yourself then you probably want to start by printing |
I've been running into this issue too, on the latest 1.8.5 firmware. When I do the
I had to edit
to:
|
Likewise, in
and L161 needs to change to:
|
Also in |
Ok, hopefully last update, this is a diff of what worked in the end, for both login and various other things. |
@avleen Thanks for all of these details. Can you confirm that you are also using a UDM Pro? What version of the server code are you running? I don't currently have access to a UDM Pro but if we can find a way to tell the difference and you are up for some testing then maybe we can build a version of this library that works with the UDM, the CloudKey and the stand-alone Java version. |
Hi Nicko!
I have the UDM (non-pro) device, which has the built-in cloud key.
I'm happy to do testing :)
…On Thu, Jan 14, 2021 at 4:28 PM Nicko van Someren ***@***.***> wrote:
@avleen <https://github.com/avleen> Thanks for all of these details. Can
you confirm that you are also using a UDM Pro? What version of the server
code are you running? I don't currently have access to a UDM Pro but if we
can find a way to tell the difference and you are up for some testing then
maybe we can build a version of this library that works with the UDM, the
CloudKey and the stand-alone Java version.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#12 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEDXBKQ7ZGEQBDU2GWEO4DSZ4LS7ANCNFSM4TP6Y2HQ>
.
|
Hello i am running in the same issue . i installed this library with |
What device and firmware version do you have @thundergreen ? |
I am running a UDM Pro with firmware 1.8.5 - and willing to test. Though my python skills are very limited. The UDM Pro hosts multiple functions. Apart from the Network Controller there is also Protect, Access and Talk. Which is why the Network API endpoints are at /proxy/network/api/s and the authentication endpoints at /api/auth. |
FYI, I'm also getting the same error with a UDM Base. The Network Controller is 6.0.43, UDM firmware is 1.8.5. I"m not sure if this helps you detect UDM*, but Quite a few defaults seem to be different: I believe hostname is always The root web application ( The latest API, via |
It would be helpful if someone (or even several people) with UDMs, CloudKeys and locally installed Java controllers could run: import requests
print(requests.get("https://<unifi IP address>:8443/status", verify=False).text)
print(requests.get("https://<unifi IP address>:443/status", verify=False).text) and send me the output. To save clogging this discussion up, maybe paste the output into a Gist and just post the link here. I'm guessing that this might be enough to let me auto-detect what sort of controller the client is trying to talk to. |
Hey Nicko,
At least on the 1.8.5 firmware on the UDM (non-pro), that URL doesn't work
any more:
1. Port 8443 isn't used any more
2. /status isn't a valid URL any more, it returns this:
https://gist.github.com/avleen/b57408d4da00751baa2b6c6ef1e373f0
…On Mon, Jan 25, 2021 at 10:28 PM Nicko van Someren ***@***.***> wrote:
It would be helpful if someone (or even several people) with UDMs,
CloudKeys and locally installed Java controllers could run:
import requestsprint(requests.get("https://<unifi IP address>:8443/status", verify=False).text)print(requests.get("https://<unifi IP address>:443/status", verify=False).text)
and send me the output.
To save clogging this discussion up, maybe paste the output into a Gist
<https://gist.github.com> and just post the link here. I'm guessing that
this might be enough to let me auto-detect what sort of controller the
client is trying to talk to.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#12 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEDXBPZGZOKTJFDE6YCGKLS3XV7HANCNFSM4TP6Y2HQ>
.
|
Can you try |
Unauthenticated this doesn't work.
Authenticated I get back:
```
{"meta":{"rc":"ok","uuid":"<uuid_stripped>"},"data":[]}
```
…On Mon, Jan 25, 2021 at 10:50 PM Nicko van Someren ***@***.***> wrote:
Can you try https://<unifi IP address>:443/proxy/network/status?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#12 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEDXBJGPVOQSCMU7TW7HYLS3XYUBANCNFSM4TP6Y2HQ>
.
|
Thanks. When you say "doesn't work", do you get a 401 result? If so, do you get something akin to: {"meta":{"rc":"error","msg":"api.err.LoginRequired"},"data":[]} in the body that is returned. Thanks. |
Yes, unauthenticated, the UDM's /proxy/network/status endpoint returns a 401. Response body is simply As verification of the response body, the response header contains:
...so, not JSON with useful information, just plain text. |
@SinisterStairs Thanks for that, although it's not what I had hoped. What do you get if you try |
Interestingly enough, I typo'd the auth login URL (I used
UPDATE: Need sleep, getting sloppy. I lost of track when I used GET or POST, and when I used basic authentication or query strings. By "hung up" I mean no immediate response to curl, and I hit ctrl-c before timing out. |
I have pushed a branch which hopefully will allow support for the Dream Machine as well as the "classic" controller. It's available in the It would be a big help if some of you could give this a try and tell me if it works. I don't have a UDM so it's basically based on the code @avleen posted. If I manage to lay my hands on a UDM I'll also try to write some reliable auto-detection code but for the moment you'll need to tell it which you're using. |
Thanks so much. I'm getting a unificontrol.exception.UnifiTransportError: 404: Not Found due to invalid credentials. I tried my UDM's local account, my Unifi Cloud account, and the root SSH password. EDIT: Will play around some more in a bit; just wanted to provide some quick feedback. |
@SinisterStairs Thanks for trying it out. In the mean time I will see if I can find access to a UDM myself. |
I tried to create a read-only user for you on my NC that could call the API w/o editing; but I don't think that's possible. If you're unable to find access to a UDM, maybe we could do a screen share sometime (e.g. Zoom). I'm on US Eastern time. EDIT: I also wanted to thank you for your persistence, supporting a device you don't even own! |
@SinisterStairs Can you try running the following code before you import import logging
logging.basicConfig(level=logging.DEBUG) |
I edited both the gist's code and comment with the latest. EDIT: To update my previous comments: Authenticating with |
Thanks for the debug output. Can you try adding a call to |
I updated the gist with the code including |
Thanks. It looks like there are several issues here:
The login and logout methods have always been a little anomalous compared to all of the other calls so I think that I will just need to have special case code to deal with these quirks. I will see what I can do. |
UniFi-CloudKey-Gen2, with 6.0.45 (Build: atag_6.0.45_14358), always gives "simplejson.errors.JSONDecodeError: Expecting value: line 2 column 1 (char 1)". Installed using pip3 and installed latest from github. |
@nickovs @thundergreen . The version of my sensor can be found here: https://github.com/clyra/unifics. The sensor uses this udm-branch (git+https://github.com/nickovs/unificontrol.git@udm-support#egg=unificontrol). @friedmanwd I guess the udm-branch is not yet merged in the master branch so you should install the library using the above url. |
I tried, same error.
…On Wed, Mar 17, 2021 at 1:40 PM clyra ***@***.***> wrote:
@nickovs <https://github.com/nickovs> @thundergreen
<https://github.com/thundergreen> . The version of my sensor can be found
here: https://github.com/clyra/unifics. The sensor uses this udm-branch
(git+
***@***.***#egg=unificontrol).
@friedmawd I guess the udm-branch is not yet merged in the master branch
so you should install the library using the above url.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#12 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ASJCANGUM2JGOAJS54ZQHDTTEDSRLANCNFSM4TP6Y2HQ>
.
|
Ignore the nut at the keyboard. I had to
set server_type=UnifiServerType.UDM), and now it it's authenticating
correctly.
It might be an idea to error handle the "Unauthorized" return.
On Wed, Mar 17, 2021 at 4:05 PM Friedman Wagner-Dobler ***@***.***>
wrote:
… I tried, same error.
On Wed, Mar 17, 2021 at 1:40 PM clyra ***@***.***> wrote:
> @nickovs <https://github.com/nickovs> @thundergreen
> <https://github.com/thundergreen> . The version of my sensor can be
> found here: https://github.com/clyra/unifics. The sensor uses this
> udm-branch (git+
> ***@***.***#egg=unificontrol
> ).
>
> @friedmawd I guess the udm-branch is not yet merged in the master branch
> so you should install the library using the above url.
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <#12 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ASJCANGUM2JGOAJS54ZQHDTTEDSRLANCNFSM4TP6Y2HQ>
> .
>
|
@friedmanwd I'm glad you got this working in the end. Yes, there needs to be some updates to this branch to make it more friendly; that's part of why I've not yet merged it onto the master branch and released it to PyPI. Hopefully I'll get a chance to do that in the next week or so. |
I recently heard some chatter about a "new API" in UniFi-OS 1.9.0 and higher. Has anyone tired @nickovs 's UDM branch on a device running 1.9.x? |
I'm on UDMP 1.90 and controller version 6.1.61 |
I'm also on UDM Pro but 1.92 firmware. I noticed that client list and other functions are working like a charm but when it comes to callable commands for instance stamgr block-sta I get an 404. I read that it might be required to add to headers: "Set-Cookie: TOKEN=xxx" and "X-CSRF-TOKEN: cafeca-cafeca-cafeca-cafecafe" You could have a look here: https://community.ui.com/questions/UDM-Pro-Unifi-API-Question/14e5fa72-4364-4958-b81f-fdded9e71a94#answer/5261af5c-bd81-46e2-9016-d42cdf73bc14 Any chance to fix? I already had a look at the source code but I'm not sure where to store these headers and to add them again to subsequent API requests. |
The problem is that with the upgraded UI in the more recent controller Ubiquiti moved a great swath of the command and status endpoints. While the new arrangement does seem to be somewhat better organised than the original API, I've still not reversed out all the new endpoints and checked the new command formats. Last weekend I upgraded my main controller to the latest version, since the new controller is now being pushed to all their products, not just the UDM. I will try to find some time to work on this soon but unfortunately this is purely a side project for me, so progress is not always as fast as other people would like. If others have input then I'm more than happy to accept pull requests! |
Totally understood. I double checked the version. Firmware for my UDMP is already 1.9.3. Well if you don't think it's related to the headers mentioned above how could I reverse engineer the new endpoints? I already gave a try with wireshark but no luck so far. |
Hey if someone might be interested. I was successful. My script can block / unblock clients on a UDM Pro controller based on Mac addresses. You can also scan the list of clients for keywords to filter retrieve the Mac address dynamically :)) |
Hey Linas,
thanks for your feedback. Finally I managed to adjust my python script to retrieve a list of clients, filter by Mac address dynamically and to block specific clients.
Cheers, Manuel
… On 29. Apr 2021, at 13:47, Linas Zvirblis ***@***.***> wrote:
I tried updating it for the new API, and it does somewhat work. For retrieving data at least. See #23 <#23>
However in the end I decided to go for an alternative approach and start from scratch. You can see it at TrackMan/uniman <https://github.com/TrackMan/uniman>, but be warned that it's just a prototype at this point. Although you may find something you can use.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#12 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AC5AEKFHROJBVDTV7TEPJQTTLFBNHANCNFSM4TP6Y2HQ>.
|
Please do post your script! :) |
I tried to post the script here in the comment...but the formatting is driving me nuts :) |
Finally I got it....
|
Having a similar issue, but with cloudkey that is running the same os as the UDM. Is there away to specify the server type ? Seems almost like it is being picked up as classic and not as udm. |
hey @phen0 That code works, but it isn't giving the ap's details as what I was after. Thanks for the suggestion. |
Trying to get it to work with this, https://community.home-assistant.io/t/monitoring-your-unifi-ap/259703, where it works with the original code, @phen0 |
@w1tw0lf |
Looking at getting info out of ap's. This code is what I have copied form the https://community.home-assistant.io/t/monitoring-your-unifi-ap/259703 from unificontrol import UnifiClient fill in your unifi controller credentialshost = '' ################# endpoints #################### client = UnifiClient(host=host,username=username,password=password,site=site,port=port) ########################################### numclients = len(clients) activity = round(devs[0]['uplink']['rx_bytes-r']/125000 + devs[0]['uplink']['tx_bytes-r']/125000,1) Wifi Clients and scoreRemember to adjust according to the number of your ssidswifi0clients = sum(1 for _ in re.finditer(r'\b%s\b' % re.escape('wifi0'), str(clients))) Wifi Clients Names###You can further specify the clients name in total or per ssid with the followingallclients = ",".join([str([x][0]['name']) for x in clients])wifi1clientnames = ','.join([clients[i]['name']for i in [i for i,x in enumerate(clients) if 'wifi1' in str(x)]])wifi0clientnames = ','.join([clients[i]['name']for i in [i for i,x in enumerate(clients) if 'wifi0' in str(x)]])It's been reported that this doesn't work for some users, so give it a try first.Remember to add the keys allclients, wifi1clientnames, wifi0clientnames in your final json and on your sensor's config in HA.final = json.dumps({"Clients":numclients,"Guests":numguests,"Clients_wifi0":wifi0clients ,"Clients_wifi1":wifi1clients ,"Score":score,"CPU":str(cpu),"RAM":str(ram),"Uptime":uptime,"Score_wifi0":wifi0score ,"Score_wifi1":wifi1score , print (final) |
hey @w1tw0lf it shouldn't be that complicated. With my code just add a function like:
btw Nickovs code didn't work with UDM Pro hence I developed my own little python script. It's not magic but working. |
thank you @phen0 Will play around a bit. PS: complete noob to this and still learning. |
...okay thought you're experienced with python. If you need help please gimme a shout. |
@phen0 thanks for the offer. If you can assist will be appreciated. Bashing my head around this for a week now. |
@phen0 managed to get it to work, have a look here, https://github.com/w1tw0lf/Unifi-AP-Device-info need to fix a 2 issues still with the info pulled. |
@w1tw0lf I've raised an issue in your project. Might be the better place for a discussion. |
thank you @phen0 much appreciated. |
here it's done: https://github.com/finish06/pyunifi |
Attempting to connect to my UDM Pro with the program
I get the following error
Any advice is appreciated.
Richard
The text was updated successfully, but these errors were encountered: