我有以下代码
import urllib.request
niveau_zoom_satellite = 0.0001389
def Image(coordinates, image_size, name):
d1 = "http://eumetview.eumetsat.int/geoserv/wms?LAYERS=overlay%3Ane_10m_coastline%2Coverlay%3Ane_10m_admin_0_boundary_lines_land&STYLES=&TRANSPARENT=TRUE&FORMAT=image%2Fpng8&VERSION=1.3.0&TILED=true&EXCEPTIONS=INIMAGE&SERVICE=WMS&REQUEST=GetMap&CRS=EPSG%3A4326&BBOX=47.640001058578,3.520001411438,48.880001068115,4.7600014209747&WIDTH=256&HEIGHT=256" % \
(niveau_zoom_satellite,
coordinates[0],
coordinates[1],
image_size[0] / 2,
image_size[1] / 2,
image_size[0],
image_size[1])
for line in urllib.request.urlopen(d1):
if line.startswith("<td align=left><input type=image src="):
d2 = "http://http://eumetview.eumetsat.int/%s" % (line.split("\"")[1],)
break
urllib.request.urlretrieve(d2, name)
if __name__ == '__main__':
Image((4.37337, 47.43572), (256, 256), "test.jpg")
问题是
ValueError:索引58处不支持的格式字符'A'(0x41)
答案 0 :(得分:0)
您使用网址作为%
运营商的格式字符串。但是,URL包含多个编码为%xx
的字符,其中xx是字符的十六进制代码(对于冒号:
为3A而对于斜杠/
为2F)。这些%
字符被解释为格式规范的开头。您应该使用双%
替换单%%
来逃避它们,以避免%
运算符解释,或者完全删除%
运算符并使用format
方法改为。
顺便说一句,我在你的字符串中没有看到任何实际的格式规范 - 你真正想要的是d1
的价值?
编辑所以我猜错了正确的代码是这样的:
d1 = "http://eumetview.eumetsat.int/geoserv/wms?LAYERS=overlay%3Ane_10m_coastline%2Coverlay%3Ane_10m_admin_0_boundary_lines_land&STYLES=&TRANSPARENT=TRUE&FORMAT=image%2Fpng8&VERSION=1.3.0&TILED=true&EXCEPTIONS=INIMAGE&SERVICE=WMS&REQUEST=GetMap&CRS=EPSG%3A4326&BBOX={},{},{},{}&WIDTH={}&HEIGHT={}".format(
coordinates[0],
coordinates[1],
image_size[0] / 2,
image_size[1] / 2,
image_size[0],
image_size[1])
我仍然不知道niveau_zoom_satellite在哪里适合这个。
答案 1 :(得分:0)
它在d1定义中抱怨List<Offer> offers = query.fetch("versions")
.where()
.eq("versions.currentVersion", true)
.orderBy("u1.creation desc") // <-- line with the change
.setFirstRow(0)
.setMaxRows(10)
.findPagedList().getList();
。最好在这里使用str.format()。
例如:
%3An
将生成:
d1 = "www.blabla.com/{var1}asdasd".format(var1=5)