python 上传钉钉图片

def uploadmedia(imgname):
    url_api = 'https://oapi.dingtalk.com/media/upload?access_token='
    upload_url = url_api + access_token + str('&type=image') #access_token=234567890自己的ID
    register_openers()
    datagen, headers = multipart_encode({"media": open(imgname, "rb")})
    # headers = {"Content-Type":"application/json", "Charset":"utf8"}
    request = urllib2.Request(upload_url, datagen, headers)
    result = urllib2.urlopen(request).read()
    result = json.loads(result)
    return result.get('media_id')
media_id = uploadmedia(imgname)
print media_id
上一篇:ElasticSearch 单个节点监控


下一篇:Java数组