trying to connect to Windows winRM using kerberos winrm - python-2.7

so I have tested this under several different variations. I have a lab with Windows 2008 R2 servers and RHEL6 and Python2.6 installed. I am able to use ansible as means to remote into the windows server and perform a ping (I have followed all the instructions on how to do this).
I get the problem of not being able to do this with Rhel 7 and python2.7, however I am not sure that the difference in python versions is whats stopping me.
I constantly get this hostname_override error...
[alebede#linuxbox]$ klist -a
Ticket cache: FILE:/tmp/krb5cc_37575
Default principal: Admin_alebede#mydomain.bla
Valid starting Expires Service principal
02/10/2017 11:30:32 02/10/2017 21:30:32 krbtgt/mydmain.bla#mydomain.bla
renew until 02/10/2017 21:30:32
Addresses: (none)
[alebede#linuxbox]$ python
Python 2.7.5 (default, Oct 11 2015, 17:47:16)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import winrm
>>> s = winrm.Session('WINDOWSBOX', auth=('admin_alebede#mydomain.bla', 'mypassword'), transport='kerberos')
>>> r = s.run_cmd('ipconfig', ['/all'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/winrm/__init__.py", line 37, in run_cmd
shell_id = self.protocol.open_shell()
File "/usr/lib/python2.7/site-packages/winrm/protocol.py", line 132, in open_shell
res = self.send_message(xmltodict.unparse(req))
File "/usr/lib/python2.7/site-packages/winrm/protocol.py", line 207, in send_message
return self.transport.send_message(message)
File "/usr/lib/python2.7/site-packages/winrm/transport.py", line 173, in send_message
self.session = self.build_session()
File "/usr/lib/python2.7/site-packages/winrm/transport.py", line 140, in build_session
sanitize_mutual_error_response=False)
TypeError: __init__() got an unexpected keyword argument 'hostname_override'
With ansible it looks like this, the same hostname_override error:
mywinserver.mydomain.com> WINRM CONNECT: transport=ssl endpoint=https://mywinserver.mydomain.com:5986/wsman
<mywinserver.mydomain.com> WINRM CONNECTION ERROR: the specified credentials were rejected by the server
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/ansible/plugins/connection/winrm.py", line 154, in _winrm_connect
self.shell_id = protocol.open_shell(codepage=65001) # UTF-8
File "/usr/lib/python2.7/site-packages/winrm/protocol.py", line 132, in open_shell
res = self.send_message(xmltodict.unparse(req))
File "/usr/lib/python2.7/site-packages/winrm/protocol.py", line 207, in send_message
return self.transport.send_message(message)
File "/usr/lib/python2.7/site-packages/winrm/transport.py", line 190, in send_message
raise InvalidCredentialsError("the specified credentials were rejected by the server")
InvalidCredentialsError: the specified credentials were rejected by the server
mywinserver.mydomain.com | UNREACHABLE! => {
"changed": false,
"msg": "kerberos: __init__() got an unexpected keyword argument 'hostname_override', ssl: the specified credentials were rejected by the server",
"unreachable": true
}
Let me know what else I can try, also on the Windows 2008R2 server i can see that the linux box is trying to connect in the security event log. Not sure what else is going on. Again, this works in RHEL6 on 2 different windows 2008R2 servers.

Likely you have a mismatch in versions between winrm and requests-kerberos. I had the same issue when I had winrm installed via pip and requests-kerberos install via apt.
Verify that you are using a single package manager for all installations.

Related

Redash v7 on Docker can't connect to RDS MySQL: "SSL connection error: unknown error number"

My Redash v7 server can't connect to Amazon RDS MySQL 8.0.28.
The error says "SSL connection error: unknown error number".
How can I solve this?
The server is running on Docker. Its image is redash/redash:7.0.0.b18042.
I tried replacing ca certificates file to https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem but it didn't work.
Here's the Python script reproduces the error.
Run this file on a Redash v7 container and you can see the error message.
import MySQLdb
ssl_params = {'ca': '/app/redash/query_runner/files/rds-combined-ca-bundle.pem'}
connection = MySQLdb.connect(host='<snip>',
user='<snip>',
passwd='<snip>',
db='<snip>',
port=3306,
charset='utf8',
use_unicode=True,
ssl=ssl_params,
connect_timeout=60)
cursor = connection.cursor()
cursor.execute('select count(1) from users')
data = cursor.fetchall()
print(data)
$ python example.py
Traceback (most recent call last):
File "example.py", line 13, in <module>
connect_timeout=60)
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 193, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2026, 'SSL connection error: unknown error number')
This error doesn't occur on a Redash v10 container but upgrading to v10 is not an option for now.
I found a workaround by myself.
Upgrading libmysqlclient20 package solved my issue.
libmysqlclient20 package in redash/redash:7.0.0.b18042 image are statically linked to yaSSL which doesn't support TLS v1.2+.
Upgraded libmysqlclient20 package are compiled using OpenSSL which supports TLS v1.2+.
MySQL 8.0.28 dropped support for TLS v1.1. That's why I need the latest libmysqlclient20.
SEE ALSO: https://dev.mysql.com/doc/refman/5.7/en/ssl-libraries.html

CERTIFICATE_VERIFY_FAILED in urllib2 but not requests, on Python 2.7.18

My longstanding Python 2.7.17 environment got corrupted, and so I installed Python 2.7.18 using the macOS 64-bit installer downloadable from python.org. Now I get errors when loading HTTPS sites using urllib2 but not requests.
Here is the environment, running macOS Mojave:
Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 19 2020, 20:48:48)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Works fine with requests:
>>> import requests
>>> url='https://github.com'
>>> requests.get(url)
<Response [200]>
Fails with urllib2:
>>> import urllib2
>>> urllib2.urlopen(url)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 429, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 447, in _open
'_open', req)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 407, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1241, in https_open
context=self._context)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1198, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:727)>
This occurs in both the plain 2.7.18 I installed and in virtual environments created from it. The problem is bigger than just urllib2, as certain database modules fail, too, that do not use urllib2. Moving to Python3 is not currently an option.
I tried pip install --upgrade certifi but that did not help.
Per [1] monkey-patching fixes the problem, but that is not a viable solution because this is destined to be production code.
Per [1] explicitly setting a non-verifying SSL context sometimes works, but again, it is not viable, plus it fails in certain third-party database interface code.
The answer may be in PEPP [2] or PEPP 493 [3], but the sun will swallow the earth before I understand those.
[1] urllib and "SSL: CERTIFICATE_VERIFY_FAILED" Error
[2] https://www.python.org/dev/peps/pep-0476/
[3] https://www.python.org/dev/peps/pep-0493/

Using Django in Docker unable to fetch rest api

I have built the webapp using Django and also configured for Rest api. I am able to fetch the data via curl and also by python script. Issue I'm running into, when using Docker container, when user fill in the data and submit, it goes thru and ran the python function, but it stop working at when fetching the data via api and thru errors
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/site-packages/requests/models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib64/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib64/python3.6/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I'm able to curl the URL inside the container. I get the same error when shell into the container in python3.6
sh-4.2# python3.6
Python 3.6.8 (default, May 2 2019, 20:40:44)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import requests, json
>>> url = 'http://127.0.0.1:8001/db/data/'
>>> response = requests.get(url)
>>> parsedjson = json.loads(response.text)
ERROR SAME AS ABOVE . . .
parsedjson = response.json()
ERROR SAME AS ABOVE . . .
>>> print(response.status_code)
503
>>> exit()
sh-4.2# curl http://127.0.0.1:8001/db/data/
[{"center":{"name":"ABC"},"main":{"code":{"name":"ABC"},"subnet":"10.10.12.0",...."}]
sh-4.2#
any idea? how to fix it?
thank you for the help in advance..

python: socketio-client not working

I have written this python code that uses socketio client module.
from socketIO_client import SocketIO
print "connecting to server"
socketIO = SocketIO('localhost', 8888, transports=['websocket'])
print "Connected"
def sendSocketId():
socketIO.emit('authenticate_python', "Python is connected")
def socketDisconnect():
socketIO.disconnect()
def doSomething(data):
print "message from ui : : ", data
socketIO.emit("msg_from_python","Message from python : : Hi! " + data)
try:
print socketIO.connected
if socketIO.connected:
sendSocketId()
socketIO.on('msg_from_node', doSomething)
socketIO.wait()
except Exception as e:
print "Exception : : ", e
socketDisconnect()
But when I connect to the server and run this file, it raises the following error:
Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
connecting to server
Traceback (most recent call last):
File "C:\Users\student\app.py", line 4, in <module>
socketIO = SocketIO('localhost', 8888, transports=['websocket'])
File "C:\Python27\lib\site-packages\socketIO_client\__init__.py", line 353, in __init__
resource, hurry_interval_in_seconds, **kw)
File "C:\Python27\lib\site-packages\socketIO_client\__init__.py", line 54, in __init__
self._transport
File "C:\Python27\lib\site-packages\socketIO_client\__init__.py", line 62, in _transport
self._engineIO_session = self._get_engineIO_session()
File "C:\Python27\lib\site-packages\socketIO_client\__init__.py", line 76, in _get_engineIO_session
transport.recv_packet())
StopIteration
>>>
I have no clue about this error and also there no no proper documentations as to how should we use this socketio client module.
The issue was resolved by uninstalling socket.io 2.0.0 version and installing watever version of it matches with the socketIO-client version.
This module socketIO-client-nexus fixes issue with compatible socket version socket.io protocol 1.x
https://pypi.org/project/socketIO-client-nexus/0.7.6/
which is not backwards compatible,
if you want to communicate using socket.io protocol 0.9 please use soketIO-client 0.5.7.2
https://pypi.org/project/socketIO-client/0.5.7.2/
Don't forget to change from import socketIO-client to socketIO-client-nexus

Zombie process running xlwings

I get a python error when attempting to use xlwings. Just importing xlwings seems to be sufficient to trigger the problem.
Lewis-MacBook-Air:~ lewis$ python
Python 2.7.10 |Anaconda 2.3.0 (x86_64)| (default, Oct 19 2015, 18:31:17)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import xlwings
>>> xlwings.__version__
'0.6.0'
>>> exit()
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/Users/lewis/anaconda/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/Users/lewis/anaconda/lib/python2.7/site-packages/xlwings/_xlmac.py", line 47, in clean_up
if is_excel_running():
File "/Users/lewis/anaconda/lib/python2.7/site-packages/xlwings/_xlmac.py", line 98, in is_excel_running
if proc.name() == 'Microsoft Excel':
File "/Users/lewis/anaconda/lib/python2.7/site-packages/psutil/__init__.py", line 539, in name
cmdline = self.cmdline()
File "/Users/lewis/anaconda/lib/python2.7/site-packages/psutil/__init__.py", line 592, in cmdline
return self._proc.cmdline()
File "/Users/lewis/anaconda/lib/python2.7/site-packages/psutil/_psosx.py", line 209, in wrapper
raise ZombieProcess(self.pid, self._name, self._ppid)
ZombieProcess: psutil.ZombieProcess process still exists but it's a zombie (pid=71)
Error in sys.exitfunc:
Traceback (most recent call last):
File "/Users/lewis/anaconda/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/Users/lewis/anaconda/lib/python2.7/site-packages/xlwings/_xlmac.py", line 47, in clean_up
if is_excel_running():
File "/Users/lewis/anaconda/lib/python2.7/site-packages/xlwings/_xlmac.py", line 98, in is_excel_running
if proc.name() == 'Microsoft Excel':
File "/Users/lewis/anaconda/lib/python2.7/site-packages/psutil/__init__.py", line 539, in name
cmdline = self.cmdline()
File "/Users/lewis/anaconda/lib/python2.7/site-packages/psutil/__init__.py", line 592, in cmdline
return self._proc.cmdline()
File "/Users/lewis/anaconda/lib/python2.7/site-packages/psutil/_psosx.py", line 209, in wrapper
raise ZombieProcess(self.pid, self._name, self._ppid)
psutil.ZombieProcess: psutil.ZombieProcess process still exists but it's a zombie (pid=71)
Lewis-MacBook-Air:~ lewis$
Calling python from Excel using Workbook.caller() is working fine.
I am running El Capitan 10.11.2 (Beta 5).
Any advice appreciated.
It seems that the version 3.3.0 of psutil is causing this, as logged here.
At the moment, downgrading to pip install psutil==3.2.2 should help until this is fixed.
update:
This has been fixed with v0.6.1