gpt4 book ai didi

python - 500 内部服务器错误 : Python Bottle API

转载 作者:行者123 更新时间:2023-12-01 05:01:31 25 4
gpt4 key购买 nike

我正在使用 Python - Bottle 开发一个简单的 API。

这就是我如何使用路由来启用 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'} 发送到链接 [https://sahildua2305.pythonanywhere.com/expand]] 来测试调用的方式。这给出了 500 内部错误。发送不带任何参数的相同请求不会出现错误!

请帮我纠正错误..提前致谢。

最佳答案

您可能有一个免费帐户,但他们不允许通过互联网访问除白名单网站之外的任何内容。

仅在提供参数时才收到错误的原因是,只有在存在参数时才会调用发出请求的代码(在 ExpandURL 中)。

关于python - 500 内部服务器错误 : Python Bottle API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26024718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com