cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
5655
Views
5
Helpful
7
Replies

socket.error: [Errno 113] No route to host

I was trying a python script to send email on cisco nexus 9000 series switch but it says no route to host. I can ping the host from the switch

1 Accepted Solution

Accepted Solutions

 

Dear George,

 

Thank you very much!

This had solved my problem.

 

from cisco.vrf import *
set_global_vrf('default')

 

I was out of office due to the weekend break that's why I didn't responded immediately.

 

View solution in original post

7 Replies 7

Hello,

 

post the script and the configuration of the Nexus...

 

Dear Georg,

Thank you for the reply,

 

Here is the sript

==========================

#!/bin/env python
import smtplib
import cisco
from cli import cli
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
# set_vrf('default')
# me == my email address
# you == recipient's email address
me = "at@at.com"
you = "at@at.com"
# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = "DC Interconnect Switching to VPN"
msg['From'] = me
msg['To'] = you
# Create the body of the message (a plain-text and an HTML version).
hostname = cli('show hostname').rstrip()
track = cli('show track brief')
text = hostname + " IP SLA Tracking Object 10 is UP, switching to VPN for DC Interconnectivity.\n\n" + track
# Record the MIME types of both parts - text/plain and text/html.
part1 = MIMEText(text, 'plain')
# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
msg.attach(part1)
# Send the message via local SMTP server.
s = smtplib.SMTP('10.1.18.23', 25)
# sendmail function takes 3 arguments: sender's address, recipient's address
# and message to send - here it is sent as one string.
s.sendmail(me, you, msg.as_string())
s.quit()

 

==========================

Here is the ping result

 

ping 10.1.18.23
PING 10.1.18.23 (10.1.18.23): 56 data bytes
64 bytes from 10.1.18.23: icmp_seq=0 ttl=125 time=1.352 ms
64 bytes from 10.1.18.23: icmp_seq=1 ttl=125 time=1.132 ms
64 bytes from 10.1.18.23: icmp_seq=2 ttl=125 time=0.936 ms
64 bytes from 10.1.18.23: icmp_seq=3 ttl=125 time=1.131 ms
64 bytes from 10.1.18.23: icmp_seq=4 ttl=125 time=0.915 ms

Hello,

 

this could be related to VRFs. Try and add the below to your script:

 

from cisco.vrf import *
VRF.get_vrf_name_by_id(get_global_vrf()) 'default'

 

Here is the error

 

2# python bootflash:N9K_EEM_TRACK_SLA_10_UP.py
File "/bootflash/N9K_EEM_TRACK_SLA_10_UP.py", line 8
VRF.get_vrf_name_by_id(get_global_vrf()) 'default'
^
SyntaxError: invalid syntax

Hello,

 

you commented out the set_vrf. Try the two scripts below. I am pretty sure it has to do with the vrf settings. Otherwise, post the running config of your Nexus:

 

from cisco.vrf import *
set_global_vrf('management')

 

or

 

from cisco.vrf import *
set_global_vrf('default')

 

Dear George,

 

Thank you very much!

This had solved my problem.

 

from cisco.vrf import *
set_global_vrf('default')

 

I was out of office due to the weekend break that's why I didn't responded immediately.

 

Hello,

 

good stuff, glad you got the issue resolved !

Review Cisco Networking products for a $25 gift card