【发布时间】:2019-02-25 06:13:27
【问题描述】:
我正在尝试发布 GraphQL Mutation,但遇到了我无法弄清楚的语法错误。我看到有一个关于转义/未转义字符的错误。我试过转义,双引号,单引号,不加引号。我似乎无法解决这个问题。 Traceback 下的代码。
# 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}]}]}
【问题讨论】:
-
会不会是
payload = '''后面的换行符?如果将其更改为payload = '''{"query":"mutat...会发生什么? -
这让我克服了那个错误并进入下一个错误,谢谢! @jDo