【发布时间】:2014-05-27 14:35:23
【问题描述】:
我试图从 API 中检索坐标,但其中一个 json 对象包含丹麦字母,并且我不断收到错误消息。这就是我所拥有的:
# -*- coding: utf-8 -*-
import urllib2
import json
import codecs
url='http://geo.oiorest.dk/adresser.json?postnr=1577&vejnavn=bernstorffsgade&husnr=16'
addressline = "%s, %s"
try:
data = urllib2.urlopen(url).read().decode('utf-8')
adresser = json.loads(data, encoding='utf-8')
for adresse in adresser:
print addressline % \
(adresse['etrs89koordinat']['øst'],
adresse['etrs89koordinat']['nord'])
except urllib2.HTTPError, e:
print "HTTP error: %d" % e.code
except urllib2.URLError, e:
print "Network error: %s" % e.reason.args[1]
我得到的错误:
KeyError: '\xc3\xb8st'
【问题讨论】:
-
错误是什么?键错误?你的python版本是什么?
-
我已将错误包含在内,谢谢。