UTF8 проблема отправить сообщение для Huawei Api в Python - PullRequest
0 голосов
/ 06 мая 2019

Я использую модем huawei WiFi 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>

пожалуйста, помогите мне решить проблему

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...