如何使用data1的变量赋值修复语法错误? 'data1'变量打印正确但我在json.dumps之前将变量放入JSON格式到'data'变量时出现语法错误:
def queryFileID():
with open('Payload.txt', 'r') as dd:
payload = []
for line in dd:
payload.append(line)
data1 = payload[0]
data = json.dumps({
"filters":{
"op":"in",
"content":{
"field":"files.file_id",
"value": data1 ,
"format":"TSV",
"fields":"case_id,",
"size":"1000000",
})
with open('CaseIDs.txt', 'wb') as gdc:
c = pycurl.Curl()
c.setopt(pycurl.URL, GDC_URL_legacy)
c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json'])
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, data)
c.setopt(pycurl.WRITEDATA, gdc)
c.perform()
c.close()
有效的代码:
import os
import pycurl
import json
GDC_URL_legacy = 'https://gdc-api.nci.nih.gov/legacy/files/'
data = json.dumps({
"filters":{
"op":"in",
"content":{
"field":"files.file_id",
"value":
["6998b65f-568a-4636-a6cb-07fb23e984a7",]}},
"format":"TSV",
"fields":"cases.case_id",
"size":"1000000"
})
with open('CasedIDs.txt', 'wb') as tgc:
c = pycurl.Curl()
c.setopt(pycurl.URL, GDC_URL_legacy)
c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json'])
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, data)
c.setopt(pycurl.WRITEDATA, tgc)
c.perform()
c.close()