我正在努力改变
curl -d '[[51.3, 13.4], [51.4, 13.3]]' -XPOST -H 'Content-Type: application/json' https://elevation.racemap.com/api
Curl命令转换成Python。我试过了
import urllib.request
import json
body = {'locs': [[51.3, 13.4], [51.4, 13.3]]}
myurl = "https://elevation.racemap.com/api"
req = urllib.request.Request(myurl)
req.add_header('Content-Type', 'application/json; charset=utf-8')
jsondata = json.dumps(body)
jsondataasbytes = jsondata.encode('utf-8')
req.add_header('Content-Length', len(jsondataasbytes))
print (jsondataasbytes)
response = urllib.request.urlopen(req, jsondataasbytes)
这就产生了一个错误。似乎curl在传递数组时没有指定参数名?我不知道如何形成Json来适应curl输入。你知道吗
我只想用^{} :
相关问题 更多 >
编程相关推荐