2

我正在尝试在多行字符串中使用内联变量来形成 GraphQL 查询。

query = '''query {
gapc {
    search_gapc_parts(part_number: "xxx", query: "XXX" limit: 1) {
    items {
        gapc_attributes {
        name
        value
        }

        weight_g
        length_mm
        height_mm
        weight_g
    }
    }
}
}'''

而不是 xxx 和 XXX 我想使用 p_code 和 m_name 变量,如下所示:

query = '''query {
gapc {
    search_gapc_parts(part_number: "{}", query: "{}" limit: 1) {
    items {
        gapc_attributes {
        name
        value
        }

        weight_g
        length_mm
        height_mm
        weight_g
    }
    }
}
}'''.format(p_code, m_name)

终端显示此错误:

Traceback (most recent call last):
  File "c:\Users\aguli\Рабочий стол\partly feature import\test.py", line 24, in <module>
    }'''.format(p_code, m_name)
ValueError: unexpected '{' in field name

我尝试了各种内联变量的方法,但出现了同样的错误。

4

0 回答 0