我在Python上创建了一个简单的网络服务应用程序,该应用程序公开了另一个类中的一些python函数。当我向本地主机发起请求时,它会连接到API,并且所公开的功能将按预期执行,但是任何后续请求均会导致错误。
这是我的代码:
webservice.py
#!flask/bin/python
from flask import Flask
from flask import request
import sys
sys.path.append('/src/')
from encrypto import Encrypto
app = Flask(__name__)
@app.route('/call/<function_name>/<arg>', methods=['GET'])
def callFunction(function_name: str, arg: str):
functionToCall = getattr(Encrypto(), function_name)
return str(functionToCall(arg))
if __name__ == '__main__':
app.run(host='localhost', threaded=True)
这是我作为演示运行的内容:
# concurrent requests - encrypt/decrypt
url = ["http://localhost:5000/call/encrypt/blahblah", "https://localhost:5000/call/encrypt/oranges",
"https://localhost:5000/call/decrypt/apples"]
w = WebGet().geturls(url,10)
print(w)
它导致以下错误:
Error HTTPSConnectionPool(host='localhost', port=5000): Max retries exceeded with url: /call/encrypt/oranges (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'SSL23_GET_SERVER_HELLO', 'unknown protocol')],)",),)): Could not access this url: https://localhost:5000/call/encrypt/oranges
Error HTTPSConnectionPool(host='localhost', port=5000): Max retries exceeded with url: /call/decrypt/apples (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'SSL23_GET_SERVER_HELLO', 'unknown protocol')],)",),)): Could not access this url: https://localhost:5000/call/decrypt/apples
[('http://localhost:5000/call/encrypt/blahblah', b'1011989968'), ('https://localhost:5000/call/encrypt/oranges', ''), ('https://localhost:5000/call/decrypt/apples', '')]
从上面的输出中可以看到,随后的2个API调用返回一个空字符串,表示错误。