为什么在没有收到100005错误的情况下不能发送UTF-8消息?

时间:2019-05-05 18:07:52

标签: python api utf-8

我正在使用华为调制解调器Wi-Fi API。这是我在Python中的代码:

from datetime import datetime

from huaweisms.api.common import post_to_url, ApiCtx, get_from_url

def send_sms(ctx: ApiCtx, dest, msg: str):

now = datetime.now()
now_str = now.strftime("%Y-%m-%d %H:%M:%S")
dest = [dest] if isinstance(dest, str) else dest

phones_content = '\n'.join('<Phone>{}</Phone>'.format(phone) for phone in dest)
xml_data = """
    <request>
        <Index>1</Index>
        <Phones>
        {}
        </Phones>
        <Sca></Sca>
        <Content>
        this is the test this is the test test testh test htest stes this is the test tes test for test all test
        this is the test this is the test test testh test htest stes this is the test tes test for test all test
        this is the test this is the test test testh test htest stes this is the test tes test for test all test
        this is the test this is the test test testh test htest stes this is the test tes test for test all test
        this is the test this is the test test testh test htest stes this is the test tes test for test all test
        this is the test this is the test test testh test htest stes this is the test tes test for test all test
        this is the test this is the test test testh test htest stes this is the test tes test for test all test
        </Content>
        <Length>300</Length>
        <Reserved>13</Reserved>
        <Date>{}</Date>
    </request>
""".format(phones_content, now_str)

headers = {
    '__RequestVerificationToken': ctx.token,
    'X-Requested-With': 'XMLHttpRequest'
}
url = "{}/sms/send-sms".format(ctx.api_base_url)
r = post_to_url(url, xml_data, ctx, headers)
return r

此代码正常工作。可以看出,我的内容有700多个字符。

但是当我发送20个以上的UTF-8字符时,会收到100005错误,这表示格式不正确。

例如,代码适用于:

<Content>
سلام این یک پیام است
</Content>

但不适用于:

<Content>
 سلام این یک پیام است و برای پایتون ارسال شده است
</Content>

为什么?

0 个答案:

没有答案