Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

报错SDK.InvalidRegionId Can not find endpoint to access的解决 #6

Closed
ghost opened this issue Sep 1, 2018 · 1 comment
Closed

Comments

@ghost
Copy link

ghost commented Sep 1, 2018

  • 首先,要用自己的ak和sk才能运行.
  • 其次,报错
params = "{\"code\":\"12345\",\"product\":\"云通信\"}"
print(send_sms(__business_id, "我的手机号", "云通信", "SMS_137885156", params))

# 返回
b'{"Message":"params must be [a-zA-Z0-9] for verification sms","RequestId":"8AC4C6F8-F483-4AFC-87BD-30490D3A5A21","Code":"isv.INVALID_PARAMETERS"}'

难道params 不能包含子母和数字之外的字符?

简单修改demo有时能正常发送,但有时候会报错::

Traceback (most recent call last):
  File "demo_sms_send.py", line 43, in <module>
    "我的手机号", "我的签名", "模板号", params))
  File "demo_sms_send.py", line 35, in send_sms
    smsResponse = acs_client.do_action_with_exception(smsRequest)
  File "我的路径/aliyunsdkcore/client.py", line 259, in do_action_with_exception
    status, headers, body = self.implementation_of_do_action(acs_request)
  File "我的路径/aliyunsdkcore/client.py", line 224, in implementation_of_do_action
    endpoint = self._resolve_endpoint(request)
  File "我的路径/aliyunsdkcore/client.py", line 174, in _resolve_endpoint
    return endpoint_resolver.resolve_endpoint(self.__region_id, request, self._location_service)
  File "我的路径/aliyunsdkcore/profile/endpoint/endpoint_resolver.py", line 36, in resolve_endpoint
    error_msg.get_msg('SDK_INVALID_REGION_ID'))
aliyunsdkcore.acs_exception.exceptions.ClientException: SDK.InvalidRegionId Can not find endpoint to access.

代码如下:

# -*- coding: utf-8 -*-
from aliyunsdkdysmsapi.request.v20170525 import SendSmsRequest
from aliyunsdkcore.client import AcsClient
import uuid


def send_sms(ak, sk, phone_numbers, sign_name, template_code, template_param=None,
             REGION="cn-hangzhou"):
    smsRequest = SendSmsRequest.SendSmsRequest()
    # 申请的短信模板编码,必填
    smsRequest.set_TemplateCode(template_code)

    # 短信模板变量参数
    if template_param is not None:
        smsRequest.set_TemplateParam(template_param)

    # 设置业务请求流水号,必填。
    business_id = uuid.uuid1()
    smsRequest.set_OutId(business_id)

    # 短信签名
    smsRequest.set_SignName(sign_name)

    # 数据提交方式
    # smsRequest.set_method(MT.POST)

    # 数据提交格式
    # smsRequest.set_accept_format(FT.JSON)

    # 短信发送的号码列表,必填。
    smsRequest.set_PhoneNumbers(phone_numbers)

    # 调用短信发送接口,返回json
    acs_client = AcsClient(ak, sk, REGION)
    smsResponse = acs_client.do_action_with_exception(smsRequest)

    # TODO 业务处理

    return smsResponse

params = "{\"code\":\"456\"}"
print(send_sms("我的ak", "我的sk",
               "我的手机号", "我的签名", "模板号", params))
@ghost ghost changed the title DEMO要用自己的ak和sk,并报错限制params? 不定时报错怎么破? Sep 5, 2018
@ghost
Copy link
Author

ghost commented Sep 6, 2018

问题解决了,要补充下面的代码:

from aliyunsdkcore.profile import region_provider
PRODUCT_NAME = "Dysmsapi"
DOMAIN = "dysmsapi.aliyuncs.com"
region_provider.add_endpoint(PRODUCT_NAME, REGION, DOMAIN)

@ghost ghost changed the title 不定时报错怎么破? 报错SDK.InvalidRegionId Can not find endpoint to access的解决 Sep 6, 2018
@ghost ghost closed this as completed Sep 6, 2018
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants