I'm hoping someone here can answer my problem - I'm getting a 500
error when I run this code. What it should do is setup cookies, log
in, then post a file to a form. The problem is it throws an exception
at ClientCookie.ur lopen(form.clic k()). The webserver hosting the form
is fine, the python looks like it should work, I cant figure out how
to solve or debug this.
######### python code
# cookie handler
cookieJar = ClientCookie.Co okieJar()
opener =
ClientCookie.bu ild_opener(Clie ntCookie.HTTPCo okieProcessor(c ookieJar))
opener.addheade rs = [("User-agent","Mozilla/5.0 (compatible)")]
ClientCookie.in stall_opener(op ener)
fp = ClientCookie.ur lopen("http://example.com/login.user")
forms = ClientForm.Pars eResponse(fp)
fp.close()
# login
form = forms[0]
form["j_username "] = "bob" # use your userid
form["j_password "] = "1234" # use your password
fp = ClientCookie.ur lopen(form.clic k())
fp.close()
# post new file
fp = ClientCookie.ur lopen("http://example.com/form_page")
forms = ClientForm.Pars eResponse(fp)
form = forms[0]
form["reportId"] = "4239"
form.add_file(o pen("/home/filename.xml"), "text/plain",
"filename.x ml")
request = form.click()
fp = ClientCookie.ur lopen(request)
fp.close()
########### error
Traceback (most recent call last):
File "./old-import-xml.py", line 62, in upload_xml
fp = ClientCookie.ur lopen(request)
File "/usr/lib/python2.5/site-packages/ClientCookie/
_urllib2_suppor t.py", line 717, in urlopen
return _opener.open(ur l, data)
File "/usr/lib/python2.5/urllib2.py", line 387, in open
response = meth(req, response)
File "/usr/lib/python2.5/site-packages/ClientCookie/
_urllib2_suppor t.py", line 391, in http_response
"http", request, response, code, msg, hdrs)
File "/usr/lib/python2.5/urllib2.py", line 425, in error
return self._call_chai n(*args)
File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain
result = func(*args)
File "/usr/lib/python2.5/urllib2.py", line 506, in
http_error_defa ult
raise HTTPError(req.g et_full_url(), code, msg, hdrs, fp)
urllib2.HTTPErr or: HTTP Error 500: Internal Server Error
error when I run this code. What it should do is setup cookies, log
in, then post a file to a form. The problem is it throws an exception
at ClientCookie.ur lopen(form.clic k()). The webserver hosting the form
is fine, the python looks like it should work, I cant figure out how
to solve or debug this.
######### python code
# cookie handler
cookieJar = ClientCookie.Co okieJar()
opener =
ClientCookie.bu ild_opener(Clie ntCookie.HTTPCo okieProcessor(c ookieJar))
opener.addheade rs = [("User-agent","Mozilla/5.0 (compatible)")]
ClientCookie.in stall_opener(op ener)
fp = ClientCookie.ur lopen("http://example.com/login.user")
forms = ClientForm.Pars eResponse(fp)
fp.close()
# login
form = forms[0]
form["j_username "] = "bob" # use your userid
form["j_password "] = "1234" # use your password
fp = ClientCookie.ur lopen(form.clic k())
fp.close()
# post new file
fp = ClientCookie.ur lopen("http://example.com/form_page")
forms = ClientForm.Pars eResponse(fp)
form = forms[0]
form["reportId"] = "4239"
form.add_file(o pen("/home/filename.xml"), "text/plain",
"filename.x ml")
request = form.click()
fp = ClientCookie.ur lopen(request)
fp.close()
########### error
Traceback (most recent call last):
File "./old-import-xml.py", line 62, in upload_xml
fp = ClientCookie.ur lopen(request)
File "/usr/lib/python2.5/site-packages/ClientCookie/
_urllib2_suppor t.py", line 717, in urlopen
return _opener.open(ur l, data)
File "/usr/lib/python2.5/urllib2.py", line 387, in open
response = meth(req, response)
File "/usr/lib/python2.5/site-packages/ClientCookie/
_urllib2_suppor t.py", line 391, in http_response
"http", request, response, code, msg, hdrs)
File "/usr/lib/python2.5/urllib2.py", line 425, in error
return self._call_chai n(*args)
File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain
result = func(*args)
File "/usr/lib/python2.5/urllib2.py", line 506, in
http_error_defa ult
raise HTTPError(req.g et_full_url(), code, msg, hdrs, fp)
urllib2.HTTPErr or: HTTP Error 500: Internal Server Error
Comment