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

winrm: can't login with russian symbols #21183

Closed
lexxcbrm opened this issue Feb 9, 2017 · 11 comments
Closed

winrm: can't login with russian symbols #21183

lexxcbrm opened this issue Feb 9, 2017 · 11 comments
Assignees
Labels
affects_2.2 This issue/PR affects Ansible v2.2 bug This issue/PR relates to a bug. c:plugins/connection/winrm windows Windows community
Milestone

Comments

@lexxcbrm
Copy link

lexxcbrm commented Feb 9, 2017

ISSUE TYPE

Bug Report

COMPONENT NAME

Ansible

ANSIBLE VERSION

ansible 2.2.0.1

CONFIGURATION

not any special configuration

OS / ENVIRONMENT

control machine: debian jessy minimal
remote machine: Windows 2012 R2

SUMMARY

running:
ansible 192.168.40.105 -u Админ -m win_ping

result:

192.168.40.105 | UNREACHABLE! => {
"changed": false,
"msg": "ssl: 'latin-1' codec can't encode characters in position 0-4: ordinal not in range(256)",
"unreachable": true
}

STEPS TO REPRODUCE
Create accout on Windows 2012 R2 with name Админ (russian letters).

EXPECTED RESULTS

Pass authentication.

@ansibot ansibot added affects_2.2 This issue/PR affects Ansible v2.2 bug_report needs_triage Needs a first human triage before being processed. labels Feb 9, 2017
@nitzmahone nitzmahone added this to the 2.3.0 milestone Feb 10, 2017
@nitzmahone nitzmahone self-assigned this Feb 10, 2017
@nitzmahone nitzmahone added windows Windows community c:plugins/connection/winrm and removed needs_triage Needs a first human triage before being processed. labels Feb 10, 2017
@nitzmahone
Copy link
Member

nitzmahone commented Feb 10, 2017

Is your control machine configured to use a UTF8 locale?

@nitzmahone nitzmahone changed the title Can't login with russian symbols winrm: can't login with russian symbols Feb 10, 2017
@lexxcbrm
Copy link
Author

lexxcbrm commented Feb 10, 2017

Yes. My control machine configure to use UTF8.
When I use ssh separately it works perfect. I mean then I type "ssh Админ@my_ip" in same case.

@jhawkesworth
Copy link
Contributor

I doesn't look like you are getting a winrm connection (still trying ssh I think).
do you have windows group_vars set up as described here: http://docs.ansible.com/ansible/intro_windows.html#inventory

Also please try running

ansible 192.168.40.105 -u Админ -m win_ping -vvv

(this should show connection type and give information on how far it is getting)

needs_info

@ansibot ansibot added the needs_info This issue requires further information. Please answer any outstanding questions. label Feb 10, 2017
@lexxcbrm
Copy link
Author

I got this stage already. If I try to do something with account created with english letters, then I works fine (e.g. "ansible 192.168.40.105 -u admin -m win_ping -vvv"). But it fails if account name contains russian symbols.

@ansibot ansibot removed the needs_info This issue requires further information. Please answer any outstanding questions. label Feb 10, 2017
@jhawkesworth
Copy link
Contributor

Please can you run with -vvvvv and copy the output here as this will help work out where the problem is.

Many thanks,

needs_info

@ansibot ansibot added the needs_info This issue requires further information. Please answer any outstanding questions. label Feb 10, 2017
@lexxcbrm
Copy link
Author

lexxcbrm commented Feb 10, 2017

root@ansible: ansible 192.168.40.105 -u test_admin -m win_ping
192.168.40.105 | SUCCESS => {
"changed": false,
"ping": "pong"
}
users
users
root@ansible:~# ansible 192.168.40.105 -u Админ -m win_ping -vvvvv
Using /etc/ansible/ansible.cfg as config file
Loading callback plugin minimal of type stdout, v2.0 from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/init.pyc
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/core/windows/win_ping.ps1
<192.168.40.105> ESTABLISH WINRM CONNECTION FOR USER: Админ on PORT 5986 TO 192.168.40.105
<192.168.40.105> WINRM CONNECT: transport=ssl endpoint=https://192.168.40.105:5986/wsman
<192.168.40.105> WINRM CONNECTION ERROR: 'latin-1' codec can't encode characters in position 0-4: ordinal not in range(256)
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/ansible/plugins/connection/winrm.py", line 154, in _winrm_connect
self.shell_id = protocol.open_shell(codepage=65001) # UTF-8
File "/usr/local/lib/python2.7/dist-packages/winrm/protocol.py", line 132, in open_shell
res = self.send_message(xmltodict.unparse(req))
File "/usr/local/lib/python2.7/dist-packages/winrm/protocol.py", line 207, in send_message
return self.transport.send_message(message)
File "/usr/local/lib/python2.7/dist-packages/winrm/transport.py", line 181, in send_message
prepared_request = self.session.prepare_request(request)
File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 407, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 306, in prepare
self.prepare_auth(auth, url)
File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 543, in prepare_auth
r = auth(self)
File "/usr/local/lib/python2.7/dist-packages/requests/auth.py", line 97, in call
r.headers['Authorization'] = _basic_auth_str(self.username, self.password)
File "/usr/local/lib/python2.7/dist-packages/requests/auth.py", line 61, in _basic_auth_str
username = username.encode('latin1')
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-4: ordinal not in range(256)

192.168.40.105 | UNREACHABLE! => {
"changed": false,
"msg": "ssl: 'latin-1' codec can't encode characters in position 0-4: ordinal not in range(256)",
"unreachable": true
}

@lexxcbrm
Copy link
Author

Sorry. I have posted same image double time.

@ansibot ansibot removed the needs_info This issue requires further information. Please answer any outstanding questions. label Feb 10, 2017
@lexxcbrm
Copy link
Author

Hello! Do you have a solution?

@jhawkesworth
Copy link
Contributor

So it looks like the point where it is failing is in requests library where it attempts to create the Authorization header by base64 encoding the username and password

def _basic_auth_str(username, password):
    """Returns a Basic Auth string."""

    authstr = 'Basic ' + to_native_string(
        b64encode(('%s:%s' % (username, password)).encode('latin1')).strip()
    )

    return authstr

So I think the issue is really an issue with requests, not ansible, and would need raising on their bug tracking system.

@jhawkesworth
Copy link
Contributor

I looked a bit more at this.
The problem definitely occurs in requests. A little script like the below will reproduce this.


#!/usr/bin/python
# -*- coding: utf-8 -*-

from base64 import b64encode

username = 'Админ'
password = 'a_password_would_go_here'

authstr = b64encode(('%s:%s' % (username, password)).encode('latin-1')).strip()

print authstr

I suggest you raise the issue on the requests issue tracker here: https://github.com/kennethreitz/requests/issues

Because the problem lies outside ansible I am going to close this issue.

@lexxcbrm
Copy link
Author

Thank you kindly

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.2 This issue/PR affects Ansible v2.2 bug This issue/PR relates to a bug. c:plugins/connection/winrm windows Windows community
Projects
None yet
Development

No branches or pull requests

4 participants