Skip to content

Instantly share code, notes, and snippets.

@MOOOWOOO
Created April 13, 2016 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MOOOWOOO/60db4bdf87e6c014ab48ef27359c0dfc to your computer and use it in GitHub Desktop.
Save MOOOWOOO/60db4bdf87e6c014ab48ef27359c0dfc to your computer and use it in GitHub Desktop.
urllib2上传文件
# -*- coding:utf-8 -*-
import mmap
import urllib2
def Upload(fname, url):
f = open(fname, 'rb')
mmapped_file_as_string = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
# Do the request
request = urllib2.Request(url, mmapped_file_as_string)
request.add_header("Content-Type", "application/x-gzip")
response = urllib2.urlopen(request)
print response
# close everything
mmapped_file_as_string.close()
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment