0

I have the following code

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")

and the problem is

ValueError: unsupported format character 'A' (0x41) at index 58

Isdj
  • 1,835
  • 1
  • 18
  • 36
rida
  • 1
  • 1
  • What line raises the error? – Isdj May 30 '17 at 10:47
  • What line? I suspect you need to escape the `%` in the string as in this question: https://stackoverflow.com/questions/8856523/valueerror-unsupported-format-character-while-forming-strings – doctorlove May 30 '17 at 10:48
  • the error in the line 7 (image_size[1]) ((((File "C:/Users/RIDHA/.PyCharmCE2017.1/config/scratches/33.py", line 26, in Image((4.37337, 47.43572), (256, 256), "test.jpg") File "C:/Users/RIDHA/.PyCharmCE2017.1/config/scratches/33.py", line 17, in Image image_size[1]))) – rida May 30 '17 at 12:31

2 Answers2

0

You use a URL as a format string for % operator. However, the URL contains several characters that are encoded as %xx, where xx is a hexadecimal code of the character (3A for colon : and 2F for slash /). Those % characters are interpreted as beginnings of format specifications. You should either escape them by replacing single % with double %% to avoid interpretation by % operator, or get rid of the % operator altogether and use format method instead.

BTW, I don't see any actual format specifications in your string - what do you really want as value of d1?

Edit: so I'd guess the correct code is something like this:

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])

I still don't know where niveau_zoom_satellite fits into this.

Błotosmętek
  • 12,717
  • 19
  • 29
  • i just wont to download an satellite imagery – rida May 30 '17 at 12:32
  • Well, this answer didn't really make things clearer. You have an URL, and you have some variables - `niveau_zoom_satellite`, `coordinates`, `image_size` - whose values presumably should replace some parts of your URL. **Which** parts? I would assume that `image_size` contains values that should go after `WIDTH=` and `HEIGHT=` respectively, but what about the rest? – Błotosmętek May 30 '17 at 13:02
  • well, each one of this variables has a number value, for image_size yes they countains values that should go after WIDTH= and HEIGHT= respectively, but the values before that are the coordonate of image – rida May 30 '17 at 13:32
  • thak uu sir your really helpped me to find a solution by your questions ..thank uu very mutch – rida May 30 '17 at 13:49
  • can uu give me your e-mail please ? – rida May 30 '17 at 14:00
0

Its complaining about %3An in the d1 definition. Better to use str.format() here.

for example:

d1 = "www.blabla.com/{var1}asdasd".format(var1=5)

which will generate:

d1 = "www.blabla.com/5asdasd"
PdevG
  • 3,427
  • 15
  • 30