简体   繁体   中英

ValueError: Invalid format specifier python

在此处输入图像描述

for i in range (0,2):
    f'{{"requests":[{"indexName":"products","params":"query=&hitsPerPage=20&maxValuesPerFacet=1000&page="{i}"&facets=%5B%22family.name%22%2C%22wine_type.name%22%2C%22vina.name%22%2C%22cepa.name%22%2C%22linea.name%22%2C%22procedencia.name%22%2C%22wine_harvest_year%22%2C%22price%22%2C%22score%22%5D&tagFilters=&facetFilters=%5B%22family.name%3AVinos%22%5D"}]}}'

If you want to use braces inside format string you have to use it like this .
Meaning two braces instead of one when you want to insert a brace.
And only one brace when you actually want to format

This is the fixed code:

for i in range (0,2):
    f'{{{{"requests":[{{"indexName":"products","params":"query=&hitsPerPage=20&maxValuesPerFacet=1000&page="{i}"&facets=%5B%22family.name%22%2C%22wine_type.name%22%2C%22vina.name%22%2C%22cepa.name%22%2C%22linea.name%22%2C%22procedencia.name%22%2C%22wine_harvest_year%22%2C%22price%22%2C%22score%22%5D&tagFilters=&facetFilters=%5B%22family.name%3AVinos%22%5D"}}]}}}}'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM