I need help with this so what it does is simple I make a Python server and Roblox uses HTTP to request from it if a person presses the execute button on the server. which will run whatever is on the python server textbox. Simple right? it works just fine on Roblox Studio but if I go into a game I get a Request Denied.
Here is the code for it:
Roblox Server-Sided Script:
local HttpService = game:GetService("HttpService")
local url = "http://localhost:5000/poll"
while true do
local response = HttpService:GetAsync(url)
local data = HttpService:JSONDecode(response)
if data.command then
local func, err = loadstring(data.command)
if func then
func()
else
warn("Error in executing command:", err)
end
end
wait(1)
end
Python Server Code:
from flask import Flask, render_template_string, jsonify, request
app = Flask(__name__)
commands = []
HTML_TEMPLATE = """
<!DOCTYPE html>
<html>
<head>
<title>Execute Command</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f5f5f5;
}
#commandInput {
width: 400px; /* Adjust the width as needed */
height: 150px; /* Adjust the height as needed */
font-size: 16px; /* Adjust the font size as needed */
padding: 10px;
border-radius: 5px;
border: 1px solid #ccc;
margin-bottom: 10px;
resize: none; /* Prevent resizing */
}
button {
width: 100px;
padding: 10px;
font-size: 16px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
</style>
<script>
function executeCommand() {
var commandInput = document.getElementById('commandInput');
fetch('/execute', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ command: commandInput.value })
})
.then(response => response.text())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
}
</script>
</head>
<body>
<div>
<textarea id="commandInput" placeholder="Enter text"></textarea>
<button onclick="executeCommand()">Execute</button>
</div>
</body>
</html>
"""
@app.route('/')
def index():
return render_template_string(HTML_TEMPLATE)
@app.route('/execute', methods=['POST'])
def execute():
command = request.json.get('command', '')
commands.append(command)
return f"Command '{command}' added to queue"
@app.route('/poll')
def poll():
if commands:
command = commands.pop(0)
return jsonify(command=command)
return jsonify(command=None)
if __name__ == '__main__':
app.run(host='localhost', port=5000)
For further info about the error I got this screen shot it might help.