Python请求库的'\ t \ n作为响应

时间:2017-05-07 16:39:20

标签: python request urllib

我正在向API请求。我遇到的问题是响应。它是UTF-8 JSON,但我收到了\t\n的消息,我无法对其进行解码。

邮差标题信息

Connection →keep-alive
Content-Encoding →gzip
Content-Length →1199
Content-Type →application/json; charset=UTF-8
Date →Sun, 07 May 2017 16:13:24 GMT
Server →nginx
Vary →Accept-Encoding
X-Main-Language →es
X-Rate-Limit-Limit →500
X-Rate-Limit-Remaining →497
X-Rate-Limit-Reset →172
X-Total-Count →2

python中的响应:

'\t{\n    "id": 356557,\n    "name": {\n        "es": "demo-`nwadigital"\n    },\n    "description": {\n        "es": null\n    },\n    "type": null,\n    "email": "interno@nwa.digital",\n    "logo": null,\n    "contact_email": null,\n    "country": "AR",\n    "facebook": null,\n    "twitter": "https:\\/\\/twitter.com\\/",\n    "google_plus": null,\n    "instagram": "https:\\/\\/instagram.com\\/",\n    "pinterest": null,\n    "blog": null,\n    "business_id": null,\n    "business_name": null,\n    "business_address": null,\n    "address": null,\n    "phone": null,\n    "customer_accounts": "optional",\n    "plan_name": "Professional",\n    "domains": [],\n    "languages": {\n        "es": {\n            "currency": "ARS",\n            "active": true\n        },\n        "pt": {\n            "currency": "BRL",\n            "active": false\n        },\n        "en": {\n            "currency": "USD",\n            "active": false\n        }\n    },\n    "original_domain": "demonwadigital.mitiendanube.com",\n    "main_currency": "ARS",\n    "current_theme": "material",\n    "main_language": "es",\n    "admin_language": "es",\n    "created_at": "2016-11-04T18:34:48+0000",\n    "updated_at": "2016-11-04T18:34:50+0000"\n}'`
def getUrl(url):
    i_get = 3
    while i_get != 0 :
        try:
            url = Request(url)
            url.add_header('Authentication','bearer xxxxxxx')
            response = urllib.request.urlopen(url)

        except urllib.error.URLError as e:
            i_get = i_get - 1
            print('Error en el Get!' + str(i_get))
            # log Error
        else:
            i_get = 0
            #data = json.loads(response.read().decode("utf8"))
            data = response.read().decode("utf8")
    return data
getUrl('https://api.tiendanube.com/v1/xxxxx/store')

有谁知道我应该更改或添加什么?

0 个答案:

没有答案