def mep(igd, proto, eip, erip, port, localip, lport, msg):
    if port == 80:
        igd.external_ip = eip
main.quit()

def emp(igd, err, proto, ep, lip, lp, msg):
    print('ERR', file=stderr)
print(err, proto, ep, lip, lp, msg, file=stderr)
main.quit()
igd.connect('mapped-external-port', mep)
igd.connect('error-mapping-port', emp)
igd.add_port('TCP', 80, my_ip, 8080, 86400, 'web')
main.run()
Forward a port via UPnP in Python