
Untitled
By: a guest on
May 11th, 2012 | syntax:
None | size: 0.64 KB | hits: 123 | expires: Never
python: HTTP PUT with unencoded binary data
Content-Type: application/octet-stream
Content-Length: (whatever my binary data length is)
import urllib2
data = b'binary-data'
r = urllib2.Request('http://example.net/put', data,
{'Content-Type': 'application/octet-stream'})
r.get_method = lambda: 'PUT'
urllib2.urlopen(r)
PUT /put HTTP/1.1
Accept-Encoding: identity
Content-Length: 11
Host: example.net
Content-Type: application/octet-stream
Connection: close
User-Agent: Python-urllib/2.7
binary-data
# headers contains `{'Content-Type': 'application/octet-stream'}`
r = urllib2.Request(url.encode('utf-8'), data, headers)