Buenas tardes amigos todo bien? Espero que este todo bien con ustedes. Disculpen molestar, pero despues de entender y trabajar un poco con el rest api con la ayuda de bootle, me puse a hacer unas funciones para hacer post, y get de un servidor simple, solo que la funcion me queda en ciclo infinito.
Mi idea es la siguiente tengo mi servidor con la siguiente estructura: from bottle import run, get, post, request, error, route import httplib from json import loads,dumps from funcoes_links import get_links, matriz_links, record_links, list_port_links, matriz_adjacencia, matriz_adjacencia_bw from funcoes_interfaces import get_interfaces,get_ovs, get_port,get_interface_list, get_list_port_host, get_list_lb from funcoes_estatisticas import get_statistics, matriz_statistics, filter_statistics from funcoes_rest_api import keep_list, send_info_to_list, topologia @get('/monitoring/topology') def monotoring_form(): ma,ma_bw=topologia() return {"Topologia_phy": ma,"Topologia_bw": ma_bw} @post('/monitoring') def get_endpoint(): fich = request.json ip=keep_list(fich) # La funcion anterior, al ser enviado un curl de la siguiente forma: curl -H "Accept: application/json" -H "Content-type: application/json" -X POST http://193.136.93.140:8081/monitoring -d '{"endpoint":"/brain/topology"}' -v me busca la direccion ip o sea /brain/topology send_info_to_list(ip) # Esta funcion quiero que envie para la direccion ip anterior, esto es, /brain/topology envie la informacion de la topologia de mi red, para eso utilizo la peticion post de la httplib @post('/brain/topology') def post_brain(): fich=request.json ip=keep_list(fich) print ip Las funciones keep_list y send_info_to_list(ip) tienen la siguiente estructura: def keep_list(lista): list_ip=[] novo_ip=lista['endpoint'] if novo_ip not in list_ip: list_ip.append(novo_ip) return list_ip def send_info_to_list(lista): for ip in lista: print repr(ip) params2,params = topologia() params =json.dumps(params) params2=json.dumps(params2) headers = {'Content-type': 'application/json', 'Accept': 'application/json'} print 'aqui' conn = httplib.HTTPConnection("193.136.93.140:8081") print 'aqui2' conn.request("POST", ip, params, headers) print 'aqui3' response = conn.getresponse() print response.status data = response.read() print data conn.request("POST", ip, params2, headers) response = conn.getresponse() print response.status print 'resp2' + str(response) data =response.read() print 'data2' + str(data) conn.close() def topologia(): info_links =get_links() info_interfaces=get_interfaces() info,links=matriz_links(info_links) switch=get_ovs(info_interfaces) portos=list_port_links(info,switch) matriz_adjacente=matriz_adjacencia(links,switch) matriz_interface=get_port(info_interfaces) lista_host=get_interface_list(matriz_interface, portos, switch) lista_portos_host=get_list_port_host(matriz_interface,portos,switch) lista_sw"Topologia_phy":itch_bw, lista_host_bw=get_list_lb(matriz_interface,portos,switch) matriz_bw=matriz_adjacencia_bw(links,switch,lista_switch_bw) return matriz_adjacente, matriz_bw # devuelve la información de la siguiente forma: matriz_bw= [[0, "100MbFD"], ["100MbFD", 0]] matriz_adjacente= [[0, 1], [1, 0]]} El problema esta en la funcion send_info_to_list, pues sin ella no me da errores, solo que ya experimente varias ideas para aquello y no consigo. En el terminal que hago el post manual me queda asi: curl -H "Accept: application/json" -H "Content-type: application/json" -X POST http://193.136.93.140:8081/monitoring -d '{"endpoint":"/brain/topology"}' -v * About to connect() to 193.136.93.140 port 8081 (#0) * Trying 193.136.93.140... connected > POST /monitoring HTTP/1.1 > User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 > zlib/1.2.3.4 libidn/1.23 librtmp/2.3 > Host: 193.136.93.140:8081 > Accept: application/json > Content-type: application/json > Content-Length: 30 > * upload completely sent off: 30out of 30 bytes y no avanza pienso que la funcion queda en ciclo infinito. Si me pueden ayudar agradecia, si necesitan de otro tipo de informacion o asi digan que trato de me explicar mejor. Muchas gracias por vuestro tiempo ayuda y disponibilidad. Saludos cordiales, Rafael.
_______________________________________________ Python-es mailing list Python-es@python.org http://mail.python.org/mailman/listinfo/python-es FAQ: http://python-es-faq.wikidot.com/