小编Dan*_*sca的帖子

从我的 python 代码中进行 graphQL 突变,得到错误

我正在尝试从 python 更改我的 Shopify 商店。我是 graphQL 的新手,我已经能够使用 graphiQL 进行更改,但我不确定如何直接从我的代码中进行更改。

这是我的 make 查询文件,它已成功用于简单查询

`import requests 
 def make_query(self, query, url, headers):
    """
    Return query response
    """
    request = requests.post(url, json={'query': query}, headers=headers)
    if request.status_code == 200:
        return request.json()
    else:
        raise Exception("Query failed to run by returning code of {}. {}".format(request.status_code, query))`
Run Code Online (Sandbox Code Playgroud)

现在在 graphiQL 中起作用的突变的一个例子是这样的:

"mutation {customerCreate(input: {email: 'wamblamkazam@send22u.info', password: 'password'}) {userErrors { field message}customer{id}}}"

但是当我将它传递给我的 make_query 函数时,它给出了这个错误

{'errors': [{'message': 'Parse error on "\'" (error) at [1, 41]', 'locations': [{'line': 1, 'column': 41}]}]} …
Run Code Online (Sandbox Code Playgroud)

python parse-error python-requests graphql express-graphql

8
推荐指数
1
解决办法
9517
查看次数