Here is my code for a server that allows remote importing of python3 libraries.
from flask import Flask
app = Flask(__name__)
@app.route("/import/<lib>",methods=['GET'])
def remote_import(lib):
try:
exec("import %s as m" % str(lib))
fn = m.__file__
with open(fn,"r") as f:
return f.read(), 200
except Exception as e:
print(e)
return "False", 404
app.run(host="127.0.0.1",port=5000)
It compiles and runs, but when testing (curl http://localhost:5000/import/os
) I get "undefined variable 'm'".