0

直到上周,我的代码都运行良好。我正在使用 Python3.5 和 Flask '1.0.2'。Flask 抱怨了两行: response = requests.get(f'http://{node}/get_chain') 和 response = {'message': f'This transaction will be added to Block {index}'} 的错误信息如下:

response = requests.get(f'http://{node}/get_chain')
                                                 ^
SyntaxError: invalid syntax

and response = {'message': f'这个交易将被添加到区块{index}'} ^ SyntaxError: invalid syntax

我在下面附加了更多上下文作为参考。有人知道发生了什么吗?非常感谢!

4

1 回答 1

0

Python 3.5 不支持字符串插值。

所以,这个表达式:

f'http://{node}/get_chain'

不会跑。这是一个语法错误。

尝试将其更改为:

'http://{}/get_chain'.format(node)

和:

response = {'message': f'This transaction will be added to Block {index}'}

需要改为:

response = {'message': 'This transaction will be added to Block {}'.format(index)}

您也可以尝试升级到 Python 3.6 或更高版本。

于 2019-02-15T11:37:37.857 回答