使用urllib.request无法保存JPG文件的Google Maps API
我使用的是Google Maps API,静态地图,并希望以jpg的格式保存图像文件。
当我使用urllib.request.urlretrieve(url,'map_46_6.png')保存png时,
这很好。但是,当我使用urllib.request.urlretrieve(url,'map_46_6.jpg')
时,这是不起作用的。打开文件会产生错误« 不是jpg文件:以0x89 0x50 »开始。手动更改向PNG的扩展将解决它。
以下是代码 :
import urllib.request
url = 'http://maps.googleapis.com/maps/api/staticmap?scale=2¢er=46.257632,6.108669&zoom=12&size=400x400&maptype=satellite&key=xxxxx'
urllib.request.urlretrieve(url, 'map_46_6.jpg')
由于此代码是先前构建的管道的一部分,因此我需要下一步的JPG文件。
我的问题是,Urllib,Google Maps或其他可能导致此错误的其他设置?非常感谢您提前 !
I am using Google Maps API, static map, and would like to save an image file in format JPG.
When I am saving a PNG using urllib.request.urlretrieve(url, 'map_46_6.png')
this is working fine. However, when I am using urllib.request.urlretrieve(url, 'map_46_6.jpg')
, this is not working. Opening the file gives an error « Not a JPG file: starts with 0x89 0x50 ». Changing manually the extension to PNG will resolve it.
The following is the code :
import urllib.request
url = 'http://maps.googleapis.com/maps/api/staticmap?scale=2¢er=46.257632,6.108669&zoom=12&size=400x400&maptype=satellite&key=xxxxx'
urllib.request.urlretrieve(url, 'map_46_6.jpg')
As this code is part of a previously built pipeline, I would need the JPG files for the next steps.
My question is, is there a setting in Urllib, Google Maps or anything else that could result in this error? Thank you very much in advance !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方案。如果一个人想要JPG,则需要明确编码格式,
& format = jpg
如下:I have found a solution. If one wants jpg, one needs to explicitly code the format,
&format=jpg
like the following: