duangy / aliyunsdkcore Goto Github PK
View Code? Open in Web Editor NEW阿里短信SDK
License: Apache License 2.0
阿里短信SDK
License: Apache License 2.0
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))
@tietang
阿里将sdk接入分为特化调用和泛化调用,特化调用安装地址为:
pip install alibabacloud_dysmsapi20170525==2.0.24
,
泛化地址为:
pip install alibabacloud-tea-openapi
Originally posted by @duangy in #9 (comment)
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
直接把这些文件放项目中还是比较难看的。
如果已经安装这个模块(比如2.3.5或2.4.4版本,虽然官网号称支持python3.x,其实根本没做支持,包括各种print的用法都还是2.x版本的),可以直接将安装后的文件替换掉。
比如这个包安装在我的虚拟环境位置:
venv/lib/python3.4/site-packages/aliyun_python_sdk_core-2.4.4-py3.4.egg
把这个地址下aliyunsdkcore文件夹中的文件统统替换成这边下载的就行;
怎么找到这个位置?
看报错信息就知道了。
File "/root/workspace/env/lib/python3.6/site-packages/aliyunsdkcore/profile/region_provider.py", line 130, in convert_dict_to_endpointsxml
content += ''+item.keys()[0]+'\n'
TypeError: 'dict_keys' object does not support indexing
For python3, dict keys is not list
if product in user_config.user_config_endpoints:
AttributeError: module 'aliyunsdkcore.profile.region_provider' has no attribute 'user_config_endpoints'
ImportError: cannot import name 'CommonRequest' from 'aliyunsdkcore.request'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.