巨蟒个人页面-阿里云开发者社区

个人介绍

暂无个人介绍

擅长的技术

获得更多能力
通用技术能力:

暂时未有相关通用技术能力~

云产品技术能力:

暂时未有相关云产品技术能力~

阿里云技能认证

详细说明
  • 高分内容
  • 最新动态
  • 文章
  • 问答
正在加载, 请稍后...
暂无更多信息
正在加载, 请稍后...
暂无更多信息
正在加载, 请稍后...
暂无更多信息
  • 回答了问题 2019-07-17

    python 钉钉文件上传

    from urllib3 import encode_multipart_formdata
    import requests
    headers={}
    data={}
    url = 'https://oapi.dingtalk.com/media/upload?access_token=' + access_token + '&type=file'
    def post_files(url,headers,data,filename,filepath):

    """
        :param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': file-tuple}``) for multipart encoding upload.
        ``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')``
        or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content-type'`` is a string
        defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers
        to add for the file.
    """
    data['media']= ('test.py', open(r'C:\Users\Administrator\Desktop\test.py', 'rb').read())
    encode_data = encode_multipart_formdata(data)
    data = encode_data[0]
    headers['Content-Type'] = encode_data[1]
    r = requests.post(url, headers=headers, data=data)
    print(json.loads(r.text)["media_id"])
    

    from urllib3 import encode_multipart_formdata
    import requests
    headers={}
    data={}
    url = 'https://oapi.dingtalk.com/media/upload?access_token=' + access_token + '&type=file'
    def post_files(url,headers,data,filename,filepath):

    data['media']= ('test.py', open(r'C:\Users\Administrator\Desktop\test.py', 'rb').read())
    encode_data = encode_multipart_formdata(data)
    data = encode_data[0]
    headers['Content-Type'] = encode_data[1]
    r = requests.post(url, headers=headers, data=data)
    print(json.loads(r.text)["media_id"])
    踩0 评论0
正在加载, 请稍后...
滑动查看更多