Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有Python请求的后GraphQL变异_Python_Python Requests_Graphql - Fatal编程技术网

带有Python请求的后GraphQL变异

带有Python请求的后GraphQL变异,python,python-requests,graphql,Python,Python Requests,Graphql,我在发布GraphQL和Python请求时遇到问题 我的函数如下所示: def create(request): access_token = 'REDACTED' headers = { "X-Shopify-Storefront-Access-Token": access_token } mutation = """ { checkoutCreate(input: { lineItems: [{ vari

我在发布GraphQL和Python请求时遇到问题

我的函数如下所示:

def create(request):
    access_token = 'REDACTED'
    headers = {
        "X-Shopify-Storefront-Access-Token": access_token
    }


    mutation = """
    {
      checkoutCreate(input: {
        lineItems: [{ variantId: "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC80", quantity: 1 }]
      }) {
        checkout {
           id
           webUrl
           lineItems(first: 5) {
             edges {
               node {
                 title
                 quantity
               }
             }
           }
        }
      }
    }
    """

    data = (requests.post('https://catsinuniform.myshopify.com/api/graphql', json={'mutation': mutation}, headers=headers).json())


    print(data)
    return render(request, 'Stock/create.html', { 'create': data })

我收到的错误是,我的json响应中有一个错误请求“bad_request-Parameter Missing或Invalid”

即使您正在发送一个变异,您的请求正文仍然应该包含一个查询属性,该属性的值应该是表示您的操作的字符串。这有点让人困惑,但非正式地说,查询和突变都被称为“查询”(无论哪种方式,您仍然在“查询”服务器)。将您的请求更改为:

requests.post('https://catsinuniform.myshopify.com/api/graphql', json={'query': mutation}, headers=headers)

在发布问题和答案时,请注意忽略敏感信息,如凭据或令牌/密钥。您似乎发布了敏感/私人信息。请重置密码和/或撤销API密钥和令牌。你也可以编辑出信息并标记你的帖子,以便版主编辑编辑历史记录。这有点晚了!