我正在尝试从互联网下载图片,但是一旦我使用字符串格式设置,它就会给我一个错误: “ UnicodeEncodeError:'ascii'编解码器无法在位置161编码字符'\ xdf':序数不在范围(128)中” 如果我删除字符串格式的图片,则可以下载图片。
我已经尝试过编码和解码,但是没有任何效果。
def get_location(self):
self.key = self.key_entry.get()
self.location = self.location_entry.get()
self.zoom = self.zoom_entry.get()
self.type = self.type_entry.get()
self.url = "https://www.mapquestapi.com/staticmap/v4/getplacemap?key=%s&size=600,600&type=%s&imagetype=png&zoom=%s&scalebar=false&traffic=false&location=%s" % (self.key, self.type, self.zoom, self.location)
webbrowser.open_new_tab('%s' % self.url)
urllib.request.urlretrieve(self.url, "location.png")
答案 0 :(得分:0)
尝试使用utf-8
webbrowser.open_new_tab('%s' % self.url, 'utf-8')