I have also modified my code and tried to send as a cookie, but getting error messages. Here is the code:
-
-
#!/usr/bin/env python
-
# written 7/22/2007
-
# by Mark O'Connor
-
-
import urllib
-
import urllib2
-
import Cookie
-
-
def ReadSite():
-
-
-
# First, encode the data.
-
infile = open ('mouseguts1', 'r')
-
data = infile.read()
-
C = Cookie.SimpleCookie()
-
C["SUBMIT"] = data
-
#print "Here is your data:"
-
#print data
-
# Now get that file-like object again, remembering to mention the data.
-
f = urllib2.urlopen("http://genome-test.cse.ucsc.edu/cgi-bin/hgBlat?command=start", C)
-
# Read the results back.
-
s = f.read()
-
print s
-
# s.close()
-
-
and the error message:
Traceback (most recent call last):
File "<pyshell#53>", line 1, in <module>
ReadSite()
File "URLReader.py", line 20, in ReadSite
f = urllib2.urlopen("http://genome-test.cse.ucsc.edu/cgi-bin/hgBlat?command=start", C)
File "C:\Python25\lib\urllib2.py", line 121, in urlopen
return _opener.open(url, data)
File "C:\Python25\lib\urllib2.py", line 374, in open
response = self._open(req, data)
File "C:\Python25\lib\urllib2.py", line 392, in _open
'_open', req)
File "C:\Python25\lib\urllib2.py", line 353, in _call_chain
result = func(*args)
File "C:\Python25\lib\urllib2.py", line 1101, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "C:\Python25\lib\urllib2.py", line 1073, in do_open
h.request(req.get_method(), req.get_selector(), req.data, headers)
File "C:\Python25\lib\httplib.py", line 862, in request
self._send_request(method, url, body, headers)
File "C:\Python25\lib\httplib.py", line 888, in _send_request
self.send(body)
File "C:\Python25\lib\httplib.py", line 707, in send
self.sock.sendall(str)
File "<string>", line 1, in sendall
TypeError: sendall() argument 1 must be string or read-only buffer, not SimpleCookie