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

paramiko python3: stdout and stderr must be a str not bytes #45

Merged
merged 1 commit into from
Sep 6, 2018

Conversation

merinos
Copy link

@merinos merinos commented Feb 6, 2018

Paramiko doesn't work with Python3. This PR fixes the bug. Without this patch I have the following error:

In [1]: from proxmoxer import ProxmoxAPI
In [2]: proxmox = ProxmoxAPI('fproxmox_server', user='root', backend='ssh_paramiko')
In [3]: proxmox.cluster.resources.get(type='vm')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-69749f99afc9> in <module>()
----> 1 proxmox.cluster.resources.get(type='vm')

~/.venv/cmdb/lib/python3.5/site-packages/proxmoxer/core.py in get(self, *args, **params)
     82 
     83     def get(self, *args, **params):
---> 84         return self(args)._request("GET", params=params)
     85 
     86     def post(self, *args, **data):

~/.venv/cmdb/lib/python3.5/site-packages/proxmoxer/core.py in _request(self, method, data, params)
     72         else:
     73             logger.info('%s %s', method, url)
---> 74         resp = self._store["session"].request(method, url, data=data or None, params=params)
     75         logger.debug('Status code: %s, output: %s', resp.status_code, resp.content)
     76 

~/.venv/cmdb/lib/python3.5/site-packages/proxmoxer/backends/base_ssh.py in request(self, method, url, data, params, headers)
     44         full_cmd = 'pvesh {0}'.format(' '.join(filter(None, (cmd, url, translated_data))))
     45 
---> 46         stdout, stderr = self._exec(full_cmd)
     47         match = lambda s: re.match('\d\d\d [a-zA-Z]', s)
     48         # sometimes contains extra text like 'trying to acquire lock...OK'

~/.venv/cmdb/lib/python3.5/site-packages/proxmoxer/backends/ssh_paramiko.py in _exec(self, cmd)
     57         session = self.ssh_client.get_transport().open_session()
     58         session.exec_command(cmd)
---> 59         stdout = ''.join(session.makefile('rb', -1))
     60         stderr = ''.join(session.makefile_stderr('rb', -1))
     61         return stdout, stderr

TypeError: sequence item 0: expected str instance, bytes found

This PR also fixes paramiko unit tests. TestParamiko return io.BytesIO instead of a list for stdout and
stderr to look like paramiko.channel.channelfile object.

Fixes paramiko tests: return io.BytesIO instead of a list for stdout and
stderr to look like paramiko.channel.channelfile object
@coveralls
Copy link

coveralls commented Feb 6, 2018

Coverage Status

Coverage remained the same at 82.034% when pulling bad0131 on merinos:python3 into 51da685 on swayf:develop.

@com6056
Copy link

com6056 commented May 7, 2018

Any updates on getting this merged?

@jplitza
Copy link

jplitza commented Jun 1, 2018

Can confirm that this PR fixes the problem.

@swayf
Copy link
Owner

swayf commented Sep 6, 2018

sorry for the delay. =) And thank you for the PR =)

@swayf swayf merged commit ff3aac9 into swayf:develop Sep 6, 2018
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

Successfully merging this pull request may close these issues.

5 participants