-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythontest20.py
More file actions
57 lines (43 loc) · 1.22 KB
/
Copy pathpythontest20.py
File metadata and controls
57 lines (43 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import urllib
import Cookie
import httplib
import string
import base64
userid = 'butter'
passwd = 'fly'
auth = 'Basic ' + string.strip(base64.encodestring(userid + ':' + passwd))
nexturl = 'http://butter:fly@www.pythonchallenge.com/pc/hex/unreal.jpg'
myFile = urllib.urlopen(nexturl)
headers = myFile.info()
print headers
LongString = myFile.read()
#print LongString
print len(LongString)
myFile.close()
#myFile = open("unreal2.jpg","wb")
#myFile.write(LongString)
#myFile.close
conn = httplib.HTTPConnection("www.pythonchallenge.com",80)
conn.putrequest("GET", "/pc/hex/unreal.jpg")
conn.putheader('Authorization', auth)
conn.endheaders()
r1 = conn.getresponse()
print r1.status, r1.reason
headers1 = r1.getheaders()
data1 = r1.read()
print len(data1)
#print headers1
conn.close()
conn = httplib.HTTPConnection("www.pythonchallenge.com",80)
conn.putrequest("GET", "/pc/hex/unreal.jpg")
conn.putheader('Authorization', auth)
conn.putheader('Range','bytes=30203-30303')
conn.endheaders()
r1 = conn.getresponse()
print r1.status, r1.reason
headers1 = r1.getheaders()
data1 = r1.read()
print data1
myrange = headers1.index('Content-Range')
print headers1[myrange][1]
conn.close()