python使用urllib2上传文件代码,pythonurllib2,import urlli


import urllib2, osimage_path = "png\\01.png"url = 'http://byrx.net/test-url/'length = os.path.getsize(image_path)png_data = open(image_path, "rb")request = urllib2.Request(url, data=png_data)request.add_header('Cache-Control', 'no-cache')request.add_header('Content-Length', '%d' % length)request.add_header('Content-Type', 'image/png')res = urllib2.urlopen(request).read().strip()return res

评论关闭