为什么Web服务没有从其他机器调用返回任何东西

时间:2014-06-16 05:33:20

标签: python json web-services

我在同一个网络中有2台机器。在一台机器上,我创建了一个Web服务,其IP地址为(suppose 192.168.2.27),我调用Web服务的机器的IP地址为(suppose 192.168.2.51)我在python中创建了一个名为hello的Web服务,我在浏览器上打开了网络服务,例如http://192.168.2.27:8080/hello 我正在获取json输出,当我在另一台机器上打开相同的Web服务时,它正在加载很长一段时间,然后显示oops nothing can be loaded

这是我的代码,我的代码中有什么问题

from bottle import route, run, response
from json import dumps
import urllib2
from mechanize import Browser
from BeautifulSoup import BeautifulSoup
from urlparse import urlparse


import json
import sys
import csv
import re

@route('/hello')
def hello():


    text=list();
    link=list();

    req = urllib2.Request("http://www.amazon.com",
                  headers={"Content-Type": "application/json"})
    html=urllib2.urlopen(req).read()
    soup = BeautifulSoup(html)
    last_page = soup.find('div', id="nav_subcats")
    for elm in last_page.findAll('a'):
        texts = elm.text
        links = elm.get('href')
        links = links.partition("&node=")[2]
        text.append(texts)
        link.append(links)




    alltext=list();
    for i,j in zip(text,link):
        alltext.append({"name":i,"id":j})
    response.content_type = 'application/json'
    return dumps(alltext)
    print(alltext)

run(host='192.168.2.27', port=8080, debug=True)

这是终端,终端根本没有接听电话

Ershad-THs-Mac-mini:Project4 LRI$ python2.7 serving1.py
Bottle v0.12.7 server starting up (using WSGIRefServer())...
Listening on http://192.168.2.27:8080/
Hit Ctrl-C to quit.

0 个答案:

没有答案