8

I'm literally using the same code as the official Betfair Developer example, the only difference is that I'm putting the APP_KEY_HERE and SESSION_TOKEN data.

But unlike the site, Visual Studio Code is giving me an error and a crash in the terminal.

enter image description here

Terminal response:

line 11
    print json.dumps(json.loads(response.text), indent=3)
          ^
SyntaxError: invalid syntax

https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Getting+Started

enter image description here

What am I missing and what do I need to change to solve this problem?

Digital Farmer
  • 1,705
  • 5
  • 17
  • 67
  • 1
    What version of python are you using? – quamrana Jul 24 '21 at 16:59
  • 2
    It seems like VS Code is expecting you to use Python 3. It's not wrong. – Mark Jul 24 '21 at 16:59
  • 2
    The example was written for Python 2.x. In Python 3 `print` is a function, you have to put the arguments in parentheses. – Barmar Jul 24 '21 at 16:59
  • Hi mate, Python 3.9.6 – Digital Farmer Jul 24 '21 at 17:00
  • 1
    ```print(json.dumps(json.loads(response.text), indent=3))``` missing ```()``` in print function. In python 3.x you have to mention ```()``` –  Jul 24 '21 at 17:00
  • 1
    [differences between Python 2 and 3](https://www.geeksforgeeks.org/important-differences-between-python-2-x-and-python-3-x-with-examples/) – Barmar Jul 24 '21 at 17:02
  • And now return ```SyntaxError: unexpected EOF while parsing```, any tips on this error? – Digital Farmer Jul 24 '21 at 17:03
  • Thanks @Sujay solved the error and now appeared what I commented above, could you tell me something about it? – Digital Farmer Jul 24 '21 at 17:04
  • 1
    ```)``` missing. Add one more parenthesis to print function: ```print(json.dumps(json.loads(response.text), indent=3))``` –  Jul 24 '21 at 17:05
  • Oh yes @Sujay , I hadn't paid attention to that either. Your comment solved my problem, please if possible put it as an answer so I can vote as a solution. Thanks in advance! – Digital Farmer Jul 24 '21 at 17:08

2 Answers2

26

In python 3.x, you have to enclose the arguments in ().

print(json.dumps(json.loads(response.text), indent=3))
6

As mentioned in comments print "" statement is written for Python 2.x and syntax for this version is not supported in VS Code.

However, you can use from __future__ import print_function and start using print() with the old interpreter or you can switch to (previously installed) Python 3.x using CTRL+SHIFT+P -> Python:Select interpreter.

harwey1
  • 71
  • 1
  • 2