yanne / api-test

0 stars 0 forks source link

SSHLibrary put_file and get_file does not work if filename contains URL encoding #55

Closed yanne closed 10 years ago

yanne commented 10 years ago

We have problems with transferring files with SSHLibrary put_file and get_file keywords if given filename contains URL encoding characters. We have used '%2F' to encode forward slash '/' character.

E.g. an_PLMN-PLMN%2FRNC-1%2FWBTS-55_12345.xml

Strange thing is that with some machines it works and some not even if having same below listed versions.

Python 2.7 SSHLibrary 1.0 Paramiko 1.7.7.1 Pycrypto 2.3 Robot Framework 2.7.3

Error produced by this problem:

DEBUG Source pattern matched local files: 'an_PLMN-PLMN%2FRNC-1%2FWBTS-55_12345.xml' INFO Putting 'an_PLMN-PLMN%2FRNC-1%2FWBTS-55_12345.xml' to '/tmp/an_PLMN-PLMN%2FRNC-1%2FWBTS-55_12345.xml' Traceback (most recent call last): File "C:\Python27\lib\logginginit.py", line 846, in emit msg = self.format(record) File "C:\Python27\lib\logginginit.py", line 723, in format return fmt.format(record) File "C:\Python27\lib\logginginit.py", line 464, in format record.message = record.getMessage() File "C:\Python27\lib\logginginit.py", line 328, in getMessage msg = msg % self.args TypeError: not enough arguments for format string Logged from file sftp.py, line 132 Traceback (most recent call last): File "D:\python\src\lib\testingscript.py", line 20, in ssh.put_file(filename, "/tmp/") File "C:\Python27\lib\site-packages\SSHLibraryinit.py", line 540, in put_file {'CRLF': '\r\n', 'LF': '\n'}.get(newlines, None)) File "C:\Python27\lib\site-packages\SSHLibrary\client.py", line 21, in put_file remotefile = self._create_remote_file(dest, mode) File "C:\Python27\lib\site-packages\SSHLibrary\pythonclient.py", line 115, in _create_remote_file self.sftp_client.chmod(dest, mode) File "C:\Python27\lib\site-packages\paramiko\sftp_client.py", line 388, in chmod self._log(DEBUG, 'chmod(%r, %r)' % (path, mode)) File "C:\Python27\lib\site-packages\paramiko\sftp_client.py", line 114, in _log super(SFTPClient, self)._log(level, "[chan %s] " + msg, ([ self.sock.get_name() ] + list(args))) File "C:\Python27\lib\site-packages\paramiko\sftp.py", line 132, in _log self.logger.log(level, msg, args) File "C:\Python27\lib\logginginit.py", line 1203, in log

Actually if we modify paramiko's logging level the problem seems to disappear. But that's very weird solution.

import paramiko import logging logger = paramiko.util.logging.getLogger() logger.setLevel(logging.CRITICAL)

This issue was originally opened at Google Code on Aug 29, 2012.

yanne commented 10 years ago

Original comment by janne.t....@gmail.com on Aug 29, 2012.

When this works, does it actually create a file with name an_PLMN-PLMN%2FRNC-1%2FWBTS-55_12345.xml?

yanne commented 10 years ago

Original comment by janne.t....@gmail.com on Aug 29, 2012.

This seems to be a problem in Paramiko actually. It takes the path, catenates it with a debug message header and then does a Python string formatting to it, which causes the above error.

We'll have to think whether this can be worked around

yanne commented 10 years ago

Original comment by wang.yan...@gmail.com on Aug 29, 2012.

our test code: import SSHLibrary import paramiko import logging

paramiko.common.logging.basicConfig(level=logging.DEBUG)

ssh = SSHLibrary.SSHLibrary() ssh.open_connection("10.9.154.178") ssh.login("xxx", "xxxx")

ssh._client.client._transport.logger.manager.disable=logging.CRITICAL

logger = paramiko.util.logging.getLogger() logger.setLevel(logging.CRITICAL)

try: ssh.put_file("an_PLMN-PLMN%2FRNC-1%2FWBTS-55_12345.xml", "/tmp/") finally: ssh.close_all_connections() print "upload successful"

yes. "logger.setLevel(logging.CRITICAL)" can work. actually the error happened in logging module.

below is "log" method in logging module

def log(self, level, msg, *args, **kwargs):
    if not isinstance(level, int):
        if raiseExceptions:
            raise TypeError("level must be an integer")
        else:
            return
    if self.isEnabledFor(level):
        self._log(level, msg, args, **kwargs)

"logger.setLevel(logging.CRITICAL)" can let self.isEnabledFor(level) return false, so we can disable "_log" to be executed. ssh._client.client._transport.logger.manager.disable=logging.CRITICAL" can work also.

actually put of get file function is ok on some laptops, although "_log" is also executed, seems that error is catched:

INFO Putting 'an_PLMN-PLMN%2FRNC-1%2FWBTS-55_12345.xml' to '/tmp/an_PLMN-PLMN%2FRNC-1%2FWBTS-55_12345.xml' Traceback (most recent call last): File "c:\python27\lib\logginginit.py", line 844, in emit msg = self.format(record) File "c:\python27\lib\logginginit.py", line 721, in format return fmt.format(record) File "c:\python27\lib\logginginit.py", line 466, in format record.message = record.getMessage() File "c:\python27\lib\logginginit.py", line 330, in getMessage msg = msg % self.args TypeError: not enough arguments for format string Logged from file sftp.py, line 132 Traceback (most recent call last): File "c:\python27\lib\logginginit.py", line 844, in emit msg = self.format(record) File "c:\python27\lib\logginginit.py", line 721, in format return fmt.format(record) File "c:\python27\lib\logginginit.py", line 466, in format record.message = record.getMessage() File "c:\python27\lib\logginginit.py", line 330, in getMessage msg = msg % self.args TypeError: not enough arguments for format string Logged from file sftp.py, line 132 Traceback (most recent call last): File "c:\python27\lib\logginginit.py", line 844, in emit msg = self.format(record) File "c:\python27\lib\logginginit.py", line 721, in format return fmt.format(record) File "c:\python27\lib\logginginit.py", line 466, in format record.message = record.getMessage() File "c:\python27\lib\logginginit.py", line 330, in getMessage msg = msg % self.args TypeError: not enough arguments for format string Logged from file sftp.py, line 132 DEBUG:paramiko.transport.sftp:[chan 2] close(00000000) INFO:paramiko.transport.sftp:[chan 2] sftp session closed. DEBUG:paramiko.transport:[chan 2] EOF sent (2) DEBUG:paramiko.transport:EOF in transport thread upload successful

yanne commented 10 years ago

Original comment by janne.t....@gmail.com on Aug 30, 2012.

Fixed in r182