python3 无法格式化报错

servertime = int(time.time())
dada_data='{"city_name": "苏州市", "city_id": 5, "iss_type": "dada", "servertime": %s, "basefee": [["0-1公里(含1公里)", "/", "8.0元(起步价)"], ["1.0-3.0公里(含3.0公里)", "1公里", "+1.0元"], ["3.0-20.0公里(含20.0公里)", "1公里", "+2.0元"], ["20.0公里以上", "3公里", "+5.0元"], "special_person_fee": [{"text": "整单+0.0元"}, {"begin": "0", "end": "2", "percent": "40", "text": "0-2公里(含2公里)+40%"}, {"begin": "2", "end": "4", "percent": "30", "text": "2-4公里(含4公里)+30%"}, {"begin": "4", "end": "13", "percent": "20", "text": "4-13公里(含13公里)+20%"}, {"begin": "13", "end": "-1", "percent": "15", "text": "13公里以上+15%"}], "overweight_fee": [["0-5公斤(含5公斤)", "/", "不收费"], ["5.0-50.0公斤(含50.0公斤)", "1公斤", "+2.0元"], ["50.0公斤以上", "1公斤", "+0.0元"]], "night_fee": [["00:00~07:00", "+8.0元"], ["22:00~23:59", "+4.0元"]], "电动车": "+0元", "轿车": "+4.0元"}'%(str(servertime))

报错如下
TypeError: not enough arguments for format string

阅读 1.3k
1 个回答

因为你内容中还有多个%,需要转义为%%

servertime = int(time.time())
dada_data='{"city_name": "苏州市", "city_id": 5, "iss_type": "dada", "servertime": %s, "basefee": [["0-1公里(含1公里)", "/", "8.0元(起步价)"], ["1.0-3.0公里(含3.0公里)", "1公里", "+1.0元"], ["3.0-20.0公里(含20.0公里)", "1公里", "+2.0元"], ["20.0公里以上", "3公里", "+5.0元"], "special_person_fee": [{"text": "整单+0.0元"}, {"begin": "0", "end": "2", "percent": "40", "text": "0-2公里(含2公里)+40%%"}, {"begin": "2", "end": "4", "percent": "30", "text": "2-4公里(含4公里)+30%%"}, {"begin": "4", "end": "13", "percent": "20", "text": "4-13公里(含13公里)+20%%"}, {"begin": "13", "end": "-1", "percent": "15", "text": "13公里以上+15%%"}], "overweight_fee": [["0-5公斤(含5公斤)", "/", "不收费"], ["5.0-50.0公斤(含50.0公斤)", "1公斤", "+2.0元"], ["50.0公斤以上", "1公斤", "+0.0元"]], "night_fee": [["00:00~07:00", "+8.0元"], ["22:00~23:59", "+4.0元"]], "电动车": "+0元", "轿车": "+4.0元"}'%(str(servertime))
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进