Python GraphQL 客户端 - 传递变量时出现意外的标点符号
Python GraphQL Client - Unexpected punctuator when passing variables
代码:
contract="0xdAC17F958D2ee523a2206206994597C13D831ec7"
query = """
($contract: Int!) {
token(id:$contract){
name
symbol
decimals
derivedETH
tradeVolumeUSD
totalLiquidity
}
}
"""
variables = {
"contract": contract
}
data = client.execute(query=query, variables=variables)
错误:
{'errors': [{'locations': [{'column': 1, 'line': 2}], 'message': 'Unexpected `([Punctuator]`\nExpected `{`, `query`, `mutation`, `subscription` or `fragment`'}]}
我尝试了多种重新格式化的方法,但无法消除此错误!求助!
您的 GraphQL 查询必须以 query
:
开头
query($someVar: String!) {
someQuery(someArg: $someVar) {
...
}
}
代码:
contract="0xdAC17F958D2ee523a2206206994597C13D831ec7"
query = """
($contract: Int!) {
token(id:$contract){
name
symbol
decimals
derivedETH
tradeVolumeUSD
totalLiquidity
}
}
"""
variables = {
"contract": contract
}
data = client.execute(query=query, variables=variables)
错误:
{'errors': [{'locations': [{'column': 1, 'line': 2}], 'message': 'Unexpected `([Punctuator]`\nExpected `{`, `query`, `mutation`, `subscription` or `fragment`'}]}
我尝试了多种重新格式化的方法,但无法消除此错误!求助!
您的 GraphQL 查询必须以 query
:
query($someVar: String!) {
someQuery(someArg: $someVar) {
...
}
}