tags:

views:

303

answers:

3

It seems my previous description was not clear, so rewriting it.

Using python urllib2, I am automating fileupload task in my webapp. And am using Cookielib to store session information, and also I could able to successfully automate the fileupload task. Problem is, when I change the login credentials and did not supply those or supply wrong login credentials to automated python script, it still processing fileupload successfully. In this case, it should actually fail.

All I want is, how to clear the cookielib generated cookies.

Below is the code snippet....

cookies = cookielib.CookieJar()
cookies.clear_session_cookies()
#cookies.clear() tried this as well
opener = urllib2.build_opener(SmartRedirectHandler,HTTPCookieProcessor(cookies),MultipartPostHandler)

urllib2.install_opener(opener)
login_req = urllib2.Request(login_url, login_params)
res = urllib2.urlopen(login_req)
#after login, do fileupload
fileupload_req = urllib2.Request(fileupload_url, params)
response = urllib2.urlopen(import_req)

I tried using clear() and clear_session_cookies() but still cookies are not cleared.

A: 

you need to install the opener that you have built, otherwise it will just keep using the default

gnibbler
As you said, I used opener to make a request for both login and fileupload request, it is still successfull with wrong credentials. Old cookies are not getting cleared, and new credentials are not taken.
ramrajedotcom
A: 

Problem seems to be not about clearing the cookies. Actually cookies are getting cleared when I say cookieJar.clear(), but still fileupload page getting invoked with incorrect login credentials. any idea about this behaviour?

ramrajedotcom
A: 

Instead of relying on cookies, I am restricting page access based response headers. Now, I could able to stop the file upload process when wrong credentials supplied. Thanks guys.

ramrajedotcom