我正在使用Python开发一个简单的API - Bottle。
这就是我使用路由启用API HTTP请求的方式:
@route('/expand')
def expand(url = ""):
url = request.query.get('url', '')
if url == "":
return {"success" : False,
"start_url" : url,
"final_url" : "",
"url_list" : []
}
url_list = expandURL(url)
return {"success" : True,
"start_url" : url,
"final_url" : url_list[-1],
"url_list" : url_list
}
这是我得到的错误:
2014-09-24 18:50:24,930 :Traceback (most recent call last):
2014-09-24 18:50:24,933 : File "/usr/local/lib/python2.7/dist-packages/bottle.py", line 764, in _handle
2014-09-24 18:50:24,933 : return route.call(**args)
2014-09-24 18:50:24,933 : File "/usr/local/lib/python2.7/dist-packages/bottle.py", line 1575, in wrapper
2014-09-24 18:50:24,933 : rv = callback(*a, **ka)
2014-09-24 18:50:24,933 : File "/home/sahildua2305/mysite/bottle_app.py", line 41, in expand
2014-09-24 18:50:24,933 : url_list = expandURL(url)
2014-09-24 18:50:24,933 : File "/home/sahildua2305/mysite/bottle_app.py", line 9, in expandURL
2014-09-24 18:50:24,933 : return unshorten_me(url, urls)
2014-09-24 18:50:24,933 : File "/home/sahildua2305/mysite/bottle_app.py", line 14, in unshorten_me
2014-09-24 18:50:24,933 : h.request('HEAD', parsed.path)
2014-09-24 18:50:24,933 : File "/usr/lib/python2.7/httplib.py", line 973, in request
2014-09-24 18:50:24,933 : self._send_request(method, url, body, headers)
2014-09-24 18:50:24,934 : File "/usr/lib/python2.7/httplib.py", line 1007, in _send_request
2014-09-24 18:50:24,934 : self.endheaders(body)
2014-09-24 18:50:24,934 : File "/usr/lib/python2.7/httplib.py", line 969, in endheaders
2014-09-24 18:50:24,934 : self._send_output(message_body)
2014-09-24 18:50:24,934 : File "/usr/lib/python2.7/httplib.py", line 829, in _send_output
2014-09-24 18:50:24,934 : self.send(msg)
2014-09-24 18:50:24,934 : File "/usr/lib/python2.7/httplib.py", line 791, in send
2014-09-24 18:50:24,934 : self.connect()
2014-09-24 18:50:24,934 : File "/usr/lib/python2.7/httplib.py", line 772, in connect
2014-09-24 18:50:24,934 : self.timeout, self.source_address)
2014-09-24 18:50:24,934 : File "/usr/lib/python2.7/socket.py", line 571, in create_connection
2014-09-24 18:50:24,934 : raise err
2014-09-24 18:50:24,934 :error: [Errno 111] Connection refused
这是我如何通过将params={'url':'http://tuq.in/sahil'}
发送到提供500内部错误的链接[https://sahildua2305.pythonanywhere.com/expand]来测试来电。在没有任何参数的情况下发送相同的请求不会产生错误!
请帮我纠正错误.. 提前谢谢。
答案 0 :(得分:2)
您可能拥有免费帐户,并且不允许互联网访问除白名单网站之外的任何内容。
您在提供参数时仅获得错误的原因是,只有在有参数时才会调用发出请求的代码(在expandURL中)。