GraphQL 和 Python 与 JSon - 未转义字符的语法错误

我正在尝试发布一个 GraphQL Mutation 并且遇到了一个我无法弄清楚的语法错误。我看到有一个关于转义/非转义字符的错误。我试过转义,双引号,单引号,没有引号。我似乎无法解决这个问题。代码下的回溯。


# http headers for api call

headers = {

    'accept': "application/json",

    'content-type':"application/json",

    'authorization': "bearer " + token,

}


# create inventory variable for mutation 

# will convert the csv to the json input in production

inventory:[{"supplier_id":24522,"supplier_part_number":"1-1002-9-SN","quantity_on_hand":5,"item_next_availability_date":"05-01-2018T00:00:00", "discontinued":true}]



# payload of the json query to pass to the API

#GraphQL Query to pull in Purchase Order Data 

payload = '''

{"query":"mutation save_inventory($inventory: [inventoryInput]!) {

  inventory {

    save(inventory: $inventory, dry_run: true) {

      handle

    }

  }

}"}

'''


# send API call and assign response to variable

response = requests.post(api_url, data=payload, headers=headers)

错误我无法在下面弄清楚。


  {"errors":[{"message":"Syntax Error GraphQL (1:1) Unexpected <EOF>\n\n1: \n   ^\n","category":"graphql","locations":[{"l

    ine":1,"column":1}]}]}


桃花长相依
浏览 91回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python