简体   繁体   English

Quickbase API以CP1252编码返回数据,但表示它返回UTF-8

[英]Quickbase API returns data in CP1252 encoding but says it's returning UTF-8

I'm having trouble with encodings when calling the Quickbase API using Python. 使用Python调用Quickbase API时遇到编码问题。 I call the API to get a record, and specify the encoding parameter in the request as "UTF-8". 我调用API来获取记录,并将请求中的encoding参数指定为“UTF-8”。 The XML response I get back from Quickbase says it's UTF-8, because the XML starts with: 我从Quickbase回来的XML响应说它是UTF-8,因为XML开头于:

<?xml version="1.0" encoding="utf-8" ?>

However, the XML bytes are actually in encoded as CP1252. 但是,XML字节实际上编码为CP1252。 I've confirmed this because a right single quotation mark (Unicode char U+2019) is being encoded as the byte 0x92 (CP1252) rather than the UTF-8 byte sequence 0xE2 0x80 0x99. 我已经确认了这一点,因为正确的单引号(Unicode char U + 2019)被编码为字节0x92(CP1252)而不是UTF-8字节序列0xE2 0x80 0x99。 Any idea why Quickbase is saying the XML response is one encoding (UTF-8) but actually using another (CP1252)? 任何想法为什么Quickbase说XML响应是一个编码(UTF-8)但实际上使用另一个(CP1252)?

Note that I'm also passing a "Accept-Charset: utf-8" header in the request, but that has no effect. 请注意,我还在请求中传递了“Accept-Charset:utf-8”标头,但这没有任何效果。

Any idea why Quickbase is saying the XML response is one encoding (UTF-8) but actually using another (CP1252)? 任何想法为什么Quickbase说XML响应是一个编码(UTF-8)但实际上使用另一个(CP1252)?

Probably because a Quickbase developer copied-and-pasted the XML declaration without actually understanding what encoding means. 可能是因为Quickbase开发人员在没有真正理解encoding意味着什么的情况下复制并粘贴了XML声明。

The easiest workaround is to use xml_response = xml_response.decode('windows-1252').encode('UTF-8') to get a real UTF-8 string to pass to the XML parser. 最简单的解决方法是使用xml_response = xml_response.decode('windows-1252').encode('UTF-8')来获取真正的 UTF-8字符串以传递给XML解析器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM