Search code examples
pythonpython-3.7python-3.5

Python request SyntaxError: invalid syntax


I have written a Python3.7.1 code, and I need to run it in Python3.5 (because I have to run it from Raspberry), an error shows up:

teams = requests.get(f'http://api.football-data.org/v2/competitions/{league}/standings', headers=headers, timeout = 10).json()
SyntaxError: invalid syntax

The error appears on the first comma (...standings', headers...)

I suppose this is because of python3.5 don't support the same things that 3.7.

I have tried to install Python 3.7 in raspberry but have no good results

teams = requests.get(f'http://api.football-data.org/v2/competitions/{league}/standings', headers=headers, timeout = 10).json()

Thanks for the help


Solution

  • The issue here is that the f string is supported since python 3.6. As you are using python 3.5, you can use an equivalent:

    url = 'http://api.football-data.org/v2/competitions/{}/standings'.format(league)
    

    Here you can find some information about string formatting.