Reputation: 21
I'm stuck here for more than an hour but seem like not able to find the solution for my issue. Issue is that I'm not able to completely match the string output.
Actual output:
hostname#$192.168.1.1/out/c2960x-universalk9-mz.152-7.E3.bin flash:c2960x-universalk9-mz.152-7.E3.bin
Destination filename [c2960x-universalk9-mz.152-7.E3.bin]?
my code not working:
commandsend = "copy ftp://206.112.194.143/out/c2960x-universalk9-mz.152-7.E3.bin flash:c2960x-universalk9-mz.152-7.E3.bin"
output = connection.send_command(commandsend,expect_string=r'Destination filename')
output += connection.send_command('\n',expect_string=r'#')
copy ftp://x.x.x.x/out/c2960x-universalk9-mz.152-7.E3.bin flash:c2960x-universalk9-mz.152-7.E3.bin 21:11:27.067 GMT Wed May 12 2021 Traceback (most recent call last): File "./svu.py", line 292, in output = uploading_update(models,ver[0],ver[1],ver[2],ver[3]) # Send to func {'CSR1000V': ['12.2.55', File "./svu.py", line 119, in uploading_update output = connection.send_command(commandsend,expect_string=r'Destination filename') File "/home/repos/public/Python/lib/python3.6/site-packages/netmiko/base_connection.py", line 1112, in send_command search_pattern)) OSError: Search pattern never detected in send_command_expect: Destination filename
I tried using the following but it still not working
output = connection.send_command(commandsend,expect_string=r'Destination.*')
output = connection.send_command(commandsend,expect_string='Destination.*')
output = connection.send_command(commandsend,expect_string=r'Destination filename.+')
I even tried adjusting the delay factor and fast_cli=False but still the same.
When I tried using the exact output. I'm seeing the below error.
output = connection.send_command(commandsend,expect_string=r'Destination filename [c2960x-universalk9-mz.152-7.E3.bin]? ')
bad character range x-u at position 27
I this a Bug or something? Any missing option I need to use?
Upvotes: 0
Views: 1149
Reputation: 1
The problem with your expect_string=r'Destination filename [c2960x-universalk9-mz.152-7.E3.bin]? '
is, that Netmiko interprets the expect_string
parameter as a Regular Expression (regex) string, therefore what's inside the [
and ]
brackets are treated as a range of characters you're trying to match, that's where the error comes from.
In your case, you want to match the exact [
and ]
characters, so you need to escape them using \
in 'raw' strings or \\
in 'normal' strings. The same applies to ?
and .
characters, which have special meaning in regex.
Therefore the right command would be:
output = connection.send_command(commandsend,expect_string=r'Destination filename \[c2960x-universalk9-mz\.152-7\.E3\.bin\]\? ')
You can use online regex tools such as regex101 to help you build and test your regexes.
Also, if you are dealing with Cisco, I think you should look at file prompt quiet
command, which disables these kinds of prompts.
Upvotes: -1