Skip to content
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

http response error: 401 - invalid content type #75

Open
DenisBY opened this issue Feb 8, 2018 · 6 comments
Open

http response error: 401 - invalid content type #75

DenisBY opened this issue Feb 8, 2018 · 6 comments

Comments

@DenisBY
Copy link

DenisBY commented Feb 8, 2018

Getting error above on this command:

winrm -hostname "192.168.250.128" --username "user" -password "password" "ifconfig /all"

Windows has default settings, I can connect using pywinrm.

@runeimp
Copy link

runeimp commented Feb 8, 2018

I haven't tried pywinrm yet but be sure to set the following on the server for this winrm client.

winrm set winrm/config/client/auth '@{Basic="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'

Also checkout http://www.hurryupandwait.io/blog/understanding-and-troubleshooting-winrm-connection-and-authentication-a-thrill-seekers-guide-to-adventure to help debug if the above doesn't work for you.

@stefanhenseler
Copy link

stefanhenseler commented Feb 14, 2018

I had the exact same issue. Unfortunately the error message is somewhat confusing. The status code is there, and points you in to the right direction, but the error message "invalid content type" is a bit meaningless in this case. I think the reason for the "invalid content type" message is because the body is basically empty in this particular scenario. So in http.go on line 87 we get the body and then we append this to the console message. In case of 401, the body is empty and the Body() function throws its error.I think a simple "401 - Unauthorized" message would be sufficient in this case.

So, about the authentication issue. In my case the winrm set winrm/config/service '@{AllowUnencrypted="true"}' has not been set. I didn't notice the error message when I tried to configure this setting:

WSManFault
    Message
        ProviderFault
            WSManFault
                Message = WinRM firewall exception will not work since one of the network connection types on this machi
ne is set to Public. Change the network connection type to either Domain or Private and try again.

Error number:  -2144108183 0x80338169
WinRM firewall exception will not work since one of the network connection types on this machine is set to Public. Chang
e the network connection type to either Domain or Private and try again.

This is due to one of my network adapters being set to the public profile. I couldn't force it though and I didn't have time to figure out if there is a way. It seems that this exception actually prevents the setting from being configured. So you can double check it with this command:

winrm get winrm/config/service

I then used the following command to figure out which interface is configured to public.

# Get the public networks
$PubNets = Get-NetConnectionProfile -NetworkCategory Public -ErrorAction SilentlyContinue 

# Set the profile to private
foreach ($PubNet in $PubNets) {
    Set-NetConnectionProfile -InterfaceIndex $PubNet.InterfaceIndex -NetworkCategory Private
}

# Configure winrm
winrm set winrm/config/service '@{AllowUnencrypted="true"}'

# Restore network categories
foreach ($PubNet in $PubNets) {
    Set-NetConnectionProfile -InterfaceIndex $PubNet.InterfaceIndex -NetworkCategory Public
}

After this, it worked for me in my lab. This is not suitable for production use though :)

@ddrake17
Copy link

I got this error when using the API and had the wrong credentials in my winrm.NewClient call

@benjamb
Copy link

benjamb commented Dec 4, 2019

I'm hitting this error currently, despite winrm get winrm/config/service showing that AllowUnencrypted is set to true:

    AllowUnencrypted = true
    Auth
        Basic = true
        Kerberos = true
        Negotiate = true
        Certificate = false
        CredSSP = false
        CbtHardeningLevel = Relaxed
    DefaultPorts
        HTTP = 5985
        HTTPS = 5986
    IPv4Filter = *
    IPv6Filter = *
    EnableCompatibilityHttpListener = false
    EnableCompatibilityHttpsListener = false
    CertificateThumbprint
    AllowRemoteAccess = true

Is there something obvious I'm missing?

@nijave
Copy link

nijave commented Sep 27, 2022

Got this error when I didn't have Basic auth enabled. It looks like pywinrm must have been using Negotiate with username/password (I was able to leave AllowUnencrypted set to false)

@CalypsoSys
Copy link
Contributor

It's probably because the server requires NTLM authentication - I have a PR in to implement this in this repo but this seems to be not very active

you could use https://github.com/CalypsoSys/bobwinrm

see https://github.com/CalypsoSys/bobwinrmntlm for usage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants