I have an Azure Maps API call in a Jupyter Notebook that returns a map tile in .png format. The call works great, but I can't figure out how to display it as an image rather than as binary text.
- API Call:
import requests
from ipywidgets import Image
url = "https://atlas.microsoft.com/map/static/png"
querystring = {
"api-version":"1.0",
"subscription-key":"<myRedactedAPIkey>",
"layer":"basic",
"zoom":"5",
"center":"-122.3950336,47.566848",
"height":"600",
"width":"600",
"pins":"default||-121.95066667 45.9135|-121.062 46.707",
"format":"png",
"path":"ra300||-122.3950336 47.566848"
}
payload = ""
headers = {
'cache-control': "no-cache"
}
response = requests.request("GET", url, data=payload, headers=headers, params=querystring)
print(response.text)
Results in:
�PNG
IHDRX�f��sRGB���gAMA���a pHYs���o�d��IDATx^��wt,K~� �2ÕYqGg4+�iGsVgGg5Z�ќ]IT�Rs9\J䈤4r$r%�a���nv������}��wͻ������{[�By�20U\�6��@T"
��
�A�E��ֵ���|�%۶��O�N�#���dX��F��Y�p����y�l3�T�8;�Y�p�O҉#�վ8���yf����+5.����@0���q���Jތ�k��(�5�О���u���gBl�=�E���@�J����m=f�k&h��^��Z��Ms��̊\�J���if��C��:2_ <etc.>
Want:
Any advice? Thank you.
EDIT2: Here is the query that works. Thanks for your assistance everyone.
import requests
from IPython.display import Image, display
url = "https://atlas.microsoft.com/map/static/png"
payload = ""
querystring = {
"api-version":"1.0",
"subscription-key":"<myApiKeyRedacted>",
"format":"png",
"layer":"basic",
"zoom":"5",
"center":"-122.3950336,47.566848",
"height":"600",
"width":"600",
"pins":"default||-121.95066667 45.9135|-121.062 46.707",
"path":"ra300000||-122.3950336 47.566848"
}
headers = {
'cache-control': "no-cache"
}
r = requests.get(url,data=payload, headers=headers, params=querystring, stream=all)
display(Image(r.content))