接口课程作业:创建部门提示“部门长度不符合限制”

自己写的代码跟老师答疑课的是相同的,创建部门提示“部门长度不符合限制”,是需要做什么设置?

  • wework

from test_requests.api.base_api import BaseApi


class WeWork(BaseApi):
    corpid = 'ww0ff069f77ced0d7a'
    @classmethod   # 设置为类方法,不需要实例化就可以使用
    def get_token(cls, secret):  # 每个应用的secret都不同,所以设置为变量
        base_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken'
        params = {'corpid':cls.corpid, 'corpsecret':secret}
        r = requests.get(base_url,params=params)
        return r.json()['access_token']  # 提取出access_token
  • 创建部门
from test_requests.api.wework import WeWork
import requests

class Department(WeWork):
    secret = 'oKPwlYZ2bMunvnI4q6ZDr94YYZc_a4OxH2KM3oEh82k'
    # 创建部门
    def create(self,name,id,**kwargs):
        data = {'name':name,'parentid':id}
        data = data.update(kwargs)
        base_url = 'https://qyapi.weixin.qq.com/cgi-bin/department/create'
        r = requests.post(base_url,params={'access_token':WeWork.get_token(self.secret)},json=data)
        return r.json()
  • 测试用例
def test_create(self):
        r = self.department.create('hello',1)
        # assert r['errmsg'] == 'created'
        print(r)

{‘errcode’: 60001, ‘errmsg’: ‘department invalid length, hint: [1588471082_81_e808c302ccd290ff18ad3899cddeaebe], from ip: 112.96.64.161, more info at https://open.work.weixin.qq.com/devtool/query?e=60001’}

注释掉data = data.update(kwargs),就可以了

关闭