Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

237
Visualizações
No 'Access-Control-Allow-Origin' header is present on the requested resource. when running a Python script using Javascript

I am new to AJAX and Flask and I am trying to make a Chrome extension that runs a Python script from Javascript. The script moves the mouse at a certain coordinate and clicks there.

This is the Javascript code:

function click_coord() {
    $.ajax({
        url: "http://127.0.0.1:5000/click_coord/",
        type: "POST",
        success: function(resp){
        console.log(resp);
    }
    });
 }

This is the Python code:

from flask import Flask, jsonify
from flask_cors import CORS, cross_origin
from pynput.mouse import Button, Controller

app = Flask(__name__)
cors = CORS(app) 
app.config['CORS_HEADERS'] = 'Content-Type'

@app.route('/click_coord/', methods=['POST']) 
def click_coord():
    move_mouse()
    a = 15
    b = 17
    return jsonify(a+b)

def move_mouse():
    mouse = Controller()

    mouse.position = (201, 549)

    mouse.press(Button.left)
    mouse.release(Button.left)

if __name__ == "__main__":
    app.run(debug=True)

The error I get is: No 'Access-Control-Allow-Origin' header is present on the requested resource. I only get this error if I call the function "move_mouse". If I don't, the code runs properly.

I saw in another post that a person had a problem because they didn't add the correct permissions but i added: "permissions": ["tabs", "http://localhost/*"] to the Json manifest

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try adding a resource to your CORS(app, resources={r"": {"origins": ""}})

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda