我使用瓶子在远程服务器上创建了一个API。当我开始托管,然后尝试使用浏览器访问API时,请求没有响应。实际上,请求并未到达服务器本身。但是,在与wget一起使用时,我得到了所需的响应。这是代码:
from pymongo import MongoClient
import json
from twython import Twython
from bottle import route, request, response, run
client = MongoClient()
db = client.PWSocial
tweets = db.tweets
follower_count = db.follower_count
APP_KEY = 'XXXX'
APP_SECRET = 'XXXX'
OAUTH_TOKEN = 'XXXX'
OAUTH_TOKEN_SECRET = 'XXXX'
twitter = Twython(APP_KEY, APP_SECRET,OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
id_list = [57947109, 183093247, 89443197, 431336956]
@route('/')
def hello():
dict1 = {'me': 'hello'}
result = json.dumps(dict1)
return result
@route('/api/follower')
def disp_follower():
ac_id = request.query.id
fc = list(follower_count.find({'id': ac_id}))
mydict = fc[0]
del mydict['_id']
result = json.dumps(mydict)
return result
@route('/api/retweet')
def rt():
ac_id = request.query.id
retweets = db.retweets
rt = list(retweets.find({'usr_id': ac_id}))
result = json.dumps(rt)
return result
@route('/api/favorite')
def fav():
ac_id = request.query.id
retweets = db.retweets
rt = list(retweets.find({'id': ac_id}, sort=[('rt_count',-1)], limit= 100))
mydict = {}
for i in rt:
a = i.get('id')
status = twitter.show_status(id = a)
b = status.get('favorite_count')
mydict[a] = b
result = json.dumps(mydict)
return result
@route('/api/max_rt')
def most_rt():
ac_id = request.query.id
retweets = db.retweets
rt = list(retweets.find({'usr_id': ac_id}, {'usr_id':57947109},sort=[('rt_co
result = json.dumps(rt)
return result
run(host= '180.179.212.200', debug=True)
有人可以为此提出理由和解决方案吗?
答案 0 :(得分:0)
找到答案,这实际上是一个简单的防火墙问题。必须在防火墙中创建一个洞才能运行任何此类API。