sadfjdsf sdfjdsjafl
007gzs / dingtalk-sdk Goto Github PK
View Code? Open in Web Editor NEW钉钉 dingding Python SDK。 DingTalk SDK for Python http://dingtalk-sdk.readthedocs.io/zh_CN/latest/
License: GNU General Public License v3.0
钉钉 dingding Python SDK。 DingTalk SDK for Python http://dingtalk-sdk.readthedocs.io/zh_CN/latest/
License: GNU General Public License v3.0
钉钉官方API文档中注明的很多参数都不是必填的,例如这个 userid, (文档来源:https://ding-doc.dingtalk.com/doc#/serverapi2/tcwmha)
源码写的是deleterole,
self._top_request(
'dingtalk.corp.role.deleterole',
{'group_id': group_id},
result_processor=lambda x: x['role_group']
)
多个小程序切换调用发信息时, 会出现以下错误, 分析应该是缓存key都相同造成的
Error code: 41020, message: accessToken中包含的appKey与agentId不一致, 无法使用当前agentId
when I try to use dingtalk like this:
from dingtalk import SecretClient
def get_sub_dept_id_list(corp_id, corp_secret):
client = SecretClient(corp_id, corp_secret)
sub_dept_list = client.department.list_ids()
return sub_dept_list
there is a problem:
File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/dingtalk/client/init.py", line 83, in _handle_pre_request
uri = '%s%saccess_token=%s' % (uri, '&' if '?' in uri else '?', self.access_token)
File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/dingtalk/client/init.py", line 43, in access_token
token = ret['access_token']
TypeError: 'NoneType' object is not subscriptable
the access_token seems to be None
but I am sure the corp_id and corp_secret is working when I try like this:
def get_access_token(corp_id, corp_secret):
url = 'https://oapi.dingtalk.com/gettoken?corpid={}&corpsecret={}'.format(corp_id, corp_secret)
request = urllib.request.Request(url)
response = urllib.request.urlopen(request)
response_str = response.read().decode("utf-8")
response_dict = json.loads(response_str)
error_code_key = "errcode"
error_message = "errmsg"
access_token_key = "access_token"
if response_dict[error_code_key] == 0 and response_dict[error_message] == "ok":
return response_dict[access_token_key]
else:
return None
I get the access_token
if there are somthing wrong , please tell me , thank you very much!!
实际中发现大多接口调用的返回值都进行了修改。并不是返回原始的值
建议要么返回原始的值,要么在文档中详细指明会返回什么格式的值,且对不同errcode的处理方式(有些接口不同的errcode后续的处理方式也会不同)
您的项目已被收录为AiLinkLife优质项目
http://www.jiangxindc.com/view/3499
python 2.7.8(pip 9.0.1)安装时报错,
AttributeError: 'module' object has no attribute '_create_unverified_context'
修改了setup.py安装成功
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
# Legacy Python that doesn't verify HTTPS certificates by default
pass
else:
# Handle target environment that doesn't support HTTPS verification
ssl._create_default_https_context = _create_unverified_https_context
钉钉新开放2个接口
1.智能工作流-使用自有工作流,开放查询用户待办列表接口
https://ding-doc.dingtalk.com/doc#/serverapi2/riueql
2.通讯录-用户管理,开放根据手机号查询userid接口
https://ding-doc.dingtalk.com/doc#/serverapi2/ege851#soV11
其他接口更新日志:
https://ding-doc.dingtalk.com/doc#/bgb96b/dwlc0a
现有代码 ALL_CALL_BACK_TAGS 中需增加attendance_check_record、meetingroom_room_info...等类型
以下代码有误,根据钉钉对该接口的规定,dept_id_list 与 userid_list 可不传,若传不能为空:
文档链接:https://open-doc.dingtalk.com/microapp/serverapi2/pgoxpy
def asyncsend(self, msg_body, agent_id, userid_list=(), dept_id_list=(), to_all_user=False):
"""
企业会话消息异步发送
:param msg_body: BodyBase 消息体
:param agent_id: 微应用的id
:param userid_list: 接收者的用户userid列表
:param dept_id_list: 接收者的部门id列表
:param to_all_user: 是否发送给企业全部用户
:return: 任务id
"""
userid_list = ",".join(map(to_text, userid_list))
dept_id_list = ",".join(map(to_text, dept_id_list))
if isinstance(msg_body, BodyBase):
msg_body = msg_body.get_dict()
msgtype = msg_body['msgtype']
msgcontent = json.dumps(msg_body[msgtype])
return self._top_request(
'dingtalk.corp.message.corpconversation.asyncsend',
{
'msgtype': msgtype,
'agent_id': agent_id,
'msgcontent': msgcontent,
'userid_list': userid_list,
'dept_id_list': dept_id_list,
'to_all_user': to_all_user
},
result_processor=lambda x: x['task_id']
)
所以给dept_id_list=()会报错
参数配置后能够拉取到通过钉钉客户端新增的审批,但是通过该sdk创建审批时返回:
Traceback (most recent call last):
File "/Users/pitaya/PycharmProjects/jm/tools/dingding_shenpi.py", line 24, in
dingdingsp()
File "/Users/pitaya/PycharmProjects/jm/tools/dingding_shenpi.py", line 18, in dingdingsp
cc_list)
File "/Users/pitaya/.pyenv/versions/3.6.3/lib/python3.6/site-packages/dingtalk/client/api/bpms.py", line 108, in processinstance_create
result_processor=lambda x: x['process_instance_id']
File "/Users/pitaya/.pyenv/versions/3.6.3/lib/python3.6/site-packages/dingtalk/client/api/base.py", line 26, in _top_request
return self.client.top_request(method, params, format, v, simplify, partner_id, url, **kwargs)
File "/Users/pitaya/.pyenv/versions/3.6.3/lib/python3.6/site-packages/dingtalk/client/base.py", line 215, in top_request
return self._request('POST', base_url, params=reqparams, top_response_key=response_key, **kwargs)
File "/Users/pitaya/.pyenv/versions/3.6.3/lib/python3.6/site-packages/dingtalk/client/base.py", line 83, in _request
res, method, url, result_processor, top_response_key, **kwargs
File "/Users/pitaya/.pyenv/versions/3.6.3/lib/python3.6/site-packages/dingtalk/client/base.py", line 159, in _handle_result
return result if not result_processor else result_processor(result)
File "/Users/pitaya/.pyenv/versions/3.6.3/lib/python3.6/site-packages/dingtalk/client/api/bpms.py", line 108, in
result_processor=lambda x: x['process_instance_id']
KeyError: 'process_instance_id'
Python 3.6.3
def get(self, chatid):
"""
获取会话
:param chatid: 群会话的id
:return: 群会话信息
"""
return self._post(
'/chat/get',
{'chatid': chatid},
result_processor=lambda x: x['chat_info']
)
请求方式:GET(HTTPS)
请求地址:https://oapi.dingtalk.com/chat/get?access_token=ACCESS_TOKEN
for name, value in form_component_values.item():
data = {'name': name}
if isinstance(value, (list, tuple)):
if len(value) > 1:
data['ext_value'] = value[1]
value = value[0]
data['value'] = value
form_component_value_list.append(data)
form_component_values参数传入 OrderedDict出错,迭代现在应该是form_component_values.items(),望修复。
报错:the JSON object must be str, bytes or bytearray, not 'dict'
代码位置:
def addpreentry(self, name, mobile, pre_entry_time=None, op_userid=None, extend_info=None):
"""
智能人事添加企业待入职员工
:param name: 员工姓名
:param mobile: 手机号
:param pre_entry_time: 预期入职时间
:param op_userid: 操作人userid
:param extend_info: 扩展信息
:return:
"""
if isinstance(pre_entry_time, (datetime.date, datetime.datetime)):
pre_entry_time = pre_entry_time.strftime(self.DATE_TIME_FORMAT)
if isinstance(extend_info, dict):
extend_info = json.loads(extend_info)
return self._top_request(
"dingtalk.oapi.smartwork.hrm.employee.addpreentry",
optionaldict({
"param": {
"name": name,
"mobile": mobile,
"pre_entry_time": pre_entry_time,
"op_userid": op_userid,
"extend_info": extend_info
}
})
)
钉钉官方更新了审批待办,企业内部应用可以调用钉钉开放平台的待办接口,将工作流数据同步到钉钉,为企业提供了统一的工作流处理入口。
详见文档:https://open-doc.dingtalk.com/microapp/serverapi2/civf9v
这个待办接口不同于待办事项里的三个接口。
def get_call_back_failed_result(self):
"""
获取回调失败的结果
:return:
"""
return self._get('/call_back/delete_call_back')
这个接口是post的为啥最后提交的时候变成get了,看半天代码,不知道哪里变成get的
Traceback (most recent call last):
File "/usr/share/miniconda3/envs/ddapi/lib/python3.6/site-packages/dingtalk/client/base.py", line 71, in _request
res.raise_for_status()
File "/usr/share/miniconda3/envs/ddapi/lib/python3.6/site-packages/requests/models.py", line 941, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 414 Client Error: Request-URI Too Large for url: https://eco.taobao.com/router/rest?process_code=xxxxxxF&originator_user_id=123456&dept_id=456789&form_component_values=form_component_values
老师好:
钉钉 jsapi 中,有许多现成的UI,如:biz.contact.complexPicker
但这种 api ,需要权鉴计算。
请您您这个包中,有权鉴计算的 api 吗?
可以给我一个 python 权鉴计算的代码吗?
经过测试,extend_info 必须是string格式,可以不传
官方文档:https://open-doc.dingtalk.com/microapp/serverapi2/dhlu4d
def addpreentry(self, name, mobile, pre_entry_time=None, op_userid=None, extend_info=None):
"""
智能人事添加企业待入职员工
:param param: 添加待入职入参
"""
if isinstance(pre_entry_time, (datetime.date, datetime.datetime)):
pre_entry_time = pre_entry_time.strftime(self.DATE_TIME_FORMAT)
if isinstance(extend_info, dict):
extend_info = json.loads(extend_info)
return self._top_request(
"dingtalk.oapi.smartwork.hrm.employee.addpreentry",
{
"param": {
"name": name,
"mobile": mobile,
"pre_entry_time": pre_entry_time,
"op_userid": op_userid,
"extend_info": extend_info
}
}
)
https://open-doc.dingtalk.com/microapp/serverapi2/pgoxpy 发送通知通知文档
client.message.asyncsend(msg, 'xxx', ['xxx']) 异常
换了pycharm和vs,本地环境还是线上环境,都是一个问题,一开始还能执行成功,过一会就不行了,开始报错,不知道什么原因?
Exception has occurred: ImportError
cannot import name 'AppKeyClient' from 'dingtalk' (c:\Users\zuyukun\Desktop\Dingtalk\code\dingtalk.py)
File "C:\Users\zuyukun\Desktop\Dingtalk\code\dingtalk.py", line 1, in
from dingtalk import AppKeyClient, SecretClient
File "C:\Users\zuyukun\Desktop\Dingtalk\code\dingtalk.py", line 1, in
from dingtalk import AppKeyClient, SecretClient
版本1.1.9的考勤接口中,只有计算请假时长的接口,是否能增加查询指定用户请假状态的接口(请假状态查询接口的官方说明:https://open-doc.dingtalk.com/docs/api.htm?spm=a219a.7386797.0.0.51954a979eFk59&source=search&apiId=40614).
另外,看它更新的官方文档(https://open-doc.dingtalk.com/microapp/serverapi2/eev437), 获得access_token好像只要appKey和appSecret,这样是否就不需要corp_id了?谢谢!
报错:argument of type 'bool' is not iterable
官方文档:https://open-doc.dingtalk.com/microapp/serverapi2/cxls8y
def update(self, userid, record_id):
"""
更新待办事项状态
:param userid: 用户id
:param record_id: 待办事项唯一id
"""
return self._top_request(
"dingtalk.oapi.workrecord.update",
{"userid": userid, "record_id": record_id},
result_processor=lambda x: x['result']
)
按道理应该返回result �true 或者false的。不知为何没有返回值。
通过post请求上传,无官方API自定义的类FileItem将文件处理成接口能识别的模式,需要自定义个FileItem类
如题,是这些接口没开放吗?提示没有权限!
添加钉钉回调时,出现错误
DingTalkClientException at /api/dingtalk/corp/add/callback/
Error code: 71012, message: url地址访问异常,错误原因为:java.net.SocketTimeoutException: Read timed out
再刷新下又出现以下错误
Error code: 71012, message: url地址访问异常,错误原因为:http statusCode is:403
怎么解决啊,谢谢
https://dingtalk-sdk.readthedocs.io/zh_CN/latest/client/api/bpms.html#
我在dingtalk-sdk文档上看到有这个方法,但是不知道如下几个参数是什么意思,如何得到的呢?
File "xx\python\lib\site-packages\dingtalk\client\base.py", line 130, in _handle_result
if ('success' in top_result and not top_result['success']) or (
TypeError: argument of type 'bool' is not iterable
@钉钉最近增加了比较多的日志方面的API,大神有计划添加进来吗?
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.