Created
April 13, 2016 10:16
-
-
Save MOOOWOOO/60db4bdf87e6c014ab48ef27359c0dfc to your computer and use it in GitHub Desktop.
urllib2上传文件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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