Error when trying to call flask API from react app

Viewed 30

So im getting the following error; Uncaught (in promise) SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON I have googled this, and there are tonnes of people with this problem, and lots of solutions, however, non seem to work for me, or im implementing them incorrect...

Scenario - React app trying to call data from a Flask API.

Flask API code

app = Flask(__name__)

@app.route("/authURL")
def home():
    data = {
        "AuthURL":"www.google.com",
        "test123":123
    }
    return jsonify(data)

React code

import { useEffect } from 'react';

function App() {

  useEffect(() => {
    fetch("/authURL")
    .then(response => response.json()
    .then(data => {
      console.log(data)
    })
  )}, []);


  return (
    <div className="App">
      <header className="App-header">
      </header>
    </div>
  );
}

export default App;

The network suggests there is no issue with communicating between flask and react, ive tried to isolate the problem, and it seems to be with the data itself, but honestly not sure. Any help is appreciated! Thanks in advance

0 Answers
Related